对于PCG.SE上的这一挑战,需要编写一个返回/输出前N个素数的函数/程序.
但是,程序中不允许使用带有主要代码点的字符.
其中两个字符是5和e.两个字母的代码点都包含一个5.因此,\u{codepoint}这两封信不会起作用.
使用转义,我可以从代码中删除所有主要字符,除了ein return.
我可以使用System.out或者FileDescriptor.out都包含这封信e.
有没有办法返回或输出而不使用e或5?
这里的参考是我的代码与字符转义:
int[]b(int b\u0029{
int c,d,f[]\u003d{}\u003b
for(f\u003dj\u0061v\u0061.util.Arr\u0061ys.copy\u004ff(f,b\u0029\u003bb-->0\u003b\u0029
for(d\u003d0,c\u003d2\u003bf[b]<1\u003bf[b]\u003dd<1?c:f[b],d\u003d0,c\u002b\u002b\u0029
for(int h:f\u0029
d\u003dh>0&&c\u002fh*h\u003d\u003dc?1:d\u003b
return f;
}
Run Code Online (Sandbox Code Playgroud)
没有字符转义:
int[]b(int b){
int c,d,f[]={};
for(f=java.util.Arrays.copyOf(f,b);b-->0;)
for(d=0,c=2;f[b]<1;f[b]=d<1?c:f[b],d=0,c++)
for(int h:f)
d=h>0&&c/h*h==c?1:d;
return f;
}
Run Code Online (Sandbox Code Playgroud)
rge*_*man 23
我已经找到一种方法来输出素数,而不使用System.out,FileDescriptor.out或return.我的方法不使用"素数"字符.
这非常棘手,因为e它在Java包名,类名和方法名中都存在.此外,S必须禁止,因为它是83Unicode中的数字,并且83是素数.它的Unicode转义\u0053包含一个5Unicode字符53也是素数.以下是我们在这些规则下不能使用Unicode转义的所有字符:
%(37是素数,\u0025有一个5)5(53是素数,\u0035有一个5)S(83是素数,\u0053有一个5)Y(89是素数,\u0059有一个5)e(101是素数,\u0065有一个5)这消除了:
toString,fromString,parseInt,valueOf,和values.java.beans,java.net,java.lang.reflect包Class.forNamenew操作员.Logger包含的类e.以下是我们可以使用Unicode转义符的字符:
)(41是素数,\u0029是允许的)+(43是素数,\u002b是允许的)/(47是素数,\u002f是允许的);(59是素数,\u003b是允许的)=(61是素数,\u003d是允许的)C(67是素数,\u0043是允许的)G(71是素数,\u0047是允许的)I(73是素数,\u0049是允许的)O(79是素数,\u004f是允许的)a(97是素数,\u0061是允许的)k(107是素数,\u006b是允许的)q(113是素数,\u0071是允许的)尝试生成其消息包含所需输出的异常是满足Java要求的唯一方法.我们不能使用已检查的异常,因为我可以找到的所有已检查的异常都e在其名称中使用,并在每个超类中使用Throwable.我将被要求使用throws包含一个包含一个异常名称的子句e.我不能extend任何课程,因为extends包含es.
这留下了未经检查的例外情况.最有可能的用途IllegalArgumentException是不是由这个代码直接创建的,而是通过调用内置的东西来抛出IllegalArgumentException.
Enums会有所帮助,除了valueOf包含一个e.javax.crypto.Mac.getInstance有一个e; 无论如何它会抛出一个检查过的异常.javax.naming.ldap.Rdn.unescapeValue("\\b" + stringFormOfOutput)通过异常输出列表,但方法有一个e.java.util.UUID.fromString通过异常输出列表,但方法有一个S.此方法抛出DataBindingException未选中的方法.
javax.xml.bind.JAXB.unmarshal(stringFormOfOutput, Long.class)通过a输出列表DataBindingException,没有e.现在我们所要做的就是将其转换int[]为a String.通过连接数组进行字符串转换""不起作用,因为数组作为Java中的对象不会覆盖toString(). Arrays.toString是因为S.
我们可以Arrays.asList用来获取List数据.但是Arrays.asList(f)给出了一个List<int[]>而不是一个List<Integer>复杂的问题.改变的类型f来Integer[]将无法正常工作,有一个e.改变的类型f来Long[]工作.
阵列到a的转换String如下.
Long c,d,f[]...
""+Arrays.asList(f)
Run Code Online (Sandbox Code Playgroud)
代替return语句,制作方法void,然后调用unmarshal.使用Long意味着需要进行一些其他调整,例如使用long文字和fill使用零而不是默认null的数组.
void b(int b){
Long c,d,f[]={};
for(f=java.util.Arrays.copyOf(f,b),Arrays.fill(f,0L);b-->0;)
for(d=0L,c=2L;f[b]<1;f[b]=d<1?c:f[b],d=0L,c++)
for(long h:f)
d=h>0&&c/h*h==c?1:d;
javax.xml.bind.JAXB.unmarshal(""+Arrays.asList(f),Long.class);
}
Run Code Online (Sandbox Code Playgroud)
逃离"素数"字符:
void b(int b\u0029{
Lon\u0067 c,d,f[]\u003d{}\u003b
for(f\u003dj\u0061v\u0061.util.Arr\u0061ys.copy\u004ff(f,b\u0029,Arr\u0061ys.fill(f,0L\u0029\u003bb-->0\u003b\u0029
for(d\u003d0L,c\u003d2L\u003bf[b]<1\u003bf[b]\u003dd<1?c:f[b],d\u003d0L,c\u002b\u002b\u0029
for(lon\u0067 h:f\u0029
d\u003dh>0&&c\u002fh*h\u003d\u003dc?1:d\u003b
j\u0061v\u0061x.x\u006dl.bind.JAXB.un\u006d\u0061rsh\u0061l(""\u002bArr\u0061ys.\u0061sList(f\u0029, Lon\u0067.cl\u0061ss\u0029\u003b
}
Run Code Online (Sandbox Code Playgroud)
这是一个丑陋的代码,它可能不会赢得任何代码高尔夫竞赛,但它是我能用Java想到满足要求的唯一方法.
将此b方法10作为参数调用会产生以下输出,其中[29, 23, 19, 17, 13, 11, 7, 5, 3, 2]前10个为素数:
Exception in thread "main" javax.xml.bind.DataBindingException: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)]
at javax.xml.bind.JAXB.unmarshal(JAXB.java:208)
at Main.b(Main.java:34)
at Main.main(Main.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:206)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:181)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:235)
at javax.xml.bind.JAXB.unmarshal(JAXB.java:205)
... 7 more
Caused by: java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:609)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:799)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)
... 10 more
Run Code Online (Sandbox Code Playgroud)
但那怎么样public static void main(String[] args)?有一个看似不可避免的事情S.制作b static并调用b与静态初始化,以消除main其String[]要求.
st\u0061tic
{
b(10\u0029\u003b
}
st\u0061tic void b(int b\u0029{
// ...
Run Code Online (Sandbox Code Playgroud)
输出现在包含一个ExceptionInInitializerError,但输出的其余部分是完整的; 这DataBindingException是被束缚的.
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:87)
Caused by: javax.xml.bind.DataBindingException: javax.xml.bind.UnmarshalException
- with linked exception:
[java.io.FileNotFoundException: C:\dev\src\misc\[29, 23, 19, 17, 13, 11, 7, 5, 3, 2] (The system cannot find the file specified)]
at javax.xml.bind.JAXB.unmarshal(JAXB.java:208)
...
Run Code Online (Sandbox Code Playgroud)