fork download
  1. class Stackylogic
  2. {
  3. static int f(char[][]p,char[]I){int l=p.length,d=0,j=-1,c=0,k=0,i[]=new int[l];while(++j<l)if(p[j][i[j]=p[j].length-1]==60)i[k=j]--;try{for(;;k+=c>48?1:-1)c=(c=p[k][i[k]--])>49?I[d++]:c;}catch(Throwable t){}return c-48;}
  4.  
  5. static void helper(String code, String input) {
  6. // convert input to char arrays
  7. char[][] p = java.util.Arrays.stream(code.split("\n")).map(str -> str.toCharArray()).toArray(len -> new char[len][]);
  8. char[] I = input.toCharArray();
  9. System.out.println(f(p, I));
  10. }
  11.  
  12. public static void main (String[] args)
  13. {
  14. helper("1\n?<\n11\n?\n0", "00"); // NAND program example
  15. helper("1\n?<\n11\n?\n0", "01"); // NAND program example
  16. helper("1\n?<\n11\n?\n0", "10"); // NAND program example
  17. helper("1\n?<\n11\n?\n0", "11"); // NAND program example
  18. }
  19. }
Success #stdin #stdout 0.19s 320832KB
stdin
Standard input is empty
stdout
1
1
1
0