您的任务是编写一个程序,给定一个数字n,以任意顺序返回所有有效的、停止运行的长度为n的斯莫尔程序的列表。
实际上,我们使用了一个名为F2的Small操变体,它只是一个带有右无界磁带的Small操。为了解决这个问题,从磁带开始移动的程序被认为是无效的,带有不平衡括号的程序也是无效的。
因为每个n都不可能解决这个问题(因为它需要您解决停止问题),所以提交的分数将是它返回错误答案的最低的n。
每个提交最多必须是1000个字节(尽管我们也鼓励您提供一个未提交的版本)。如果打成平局,先前的答案就赢了。
N= 1:
+ >
N= 2:
++ +> >+ >< >> []
N= 3:
+++ ++> +>+ +>< +>> >++ >+< >+> ><+ ><> >>+ >>< >>> >[] [+] [<] [>] []+ []>
N= 4:
++++ +++> ++>+ ++>< ++>> +>++ +>+< +>+> +><+ +><> +>>+ +>>< +>>> >+++ >++< >++> >+<+ >+<> >+>+ >+>< >+>> ><++ ><+> ><>+ ><>< ><>> >>++ >>+< >>+> >><+ >><< >><> >>>+ >>>< >>>> [][] ++[] +>[] ><[] >>[] [++] [+<] [+>] [<+] [<<] [<>] [>+] [><] [>>] []++ []+> []>+ []>< []>> +[+] +[>] >[+] >[<] >[>] >[]+ >[]< >[]> [+]+ [+]> [<]+ [<]> [>]+ [>]> [[]]
如果还有什么我忘了补充的,请告诉我。
发布于 2017-06-06 18:23:24
这个时钟以980字节为单位,因为我有太多的工作要做,所以我决定让它更易读。基本上,我正在生成长度为n的所有可能程序,并对某些x进行n^x次数的迭代。x当前为3,但它可以任意修改到任意大小,仅限于JVM的精度限制。如果x增加,这将适用于任意大的输入值,但对于tio,我将其设置为3。
import java.util.*;
public class Main{
public static void main(String[] args){
int i = new Scanner(System.in).nextInt();
int x = 3;
l:for(int j=0;j<Math.pow(5, i);j++){
try {
String s="";
for(int k=j;s.length()<i;k/=5)
s="+<>][".charAt(k%5)+s;
Stack<Integer>y=new Stack<Integer>();
Map<Integer,Integer>f=new HashMap<>(),b=new HashMap<>();
for(int m=0; m<s.length();m++){
char c=s.charAt(m);
if(c=='[')y.push(m);
if(c==']'){int n=y.pop();f.put(n, m);b.put(m, n);}
}
if(y.size()>0)
continue;
boolean[] t= new boolean[s.length()];
int l=0,n=0;
for(long m=0;l<s.length()&m<Math.pow(i,x);l++,m++){
switch(s.charAt(l)){
case'+':t[n]=!t[n];break;
case'>':n++;break;
case'<':n--; if(n < 0)continue l;break;
case'[':if(!t[n])l=f.get(l);break;
case']':l=b.get(l)-1;break;
}
}
if(l>=s.length()){
System.out.println(s);
}
} catch(Exception e){continue;}
}
}
}
发布于 2017-06-06 07:54:42
1-?"++ +> >+ >< >> []":"+ >"|&@
从好的、简单的开始,对1和2的正确答案进行硬编码,如果n=1输出+ >
,否则输出++ +> >+ >< >> []
https://codegolf.stackexchange.com/questions/124807
复制相似问题