fork download
  1. class Main{
  2. static java.util.function.Function<byte[][], java.util.function.Consumer<byte[]>> f =
  3.  
  4. m->i->{int l=0,M=30000,x=0,y=0,p=0,d=0,c,I=0,q;for(var r:m)l=(q=r.length)>l?q:l;for(var t=new byte[M];;d=(q=">^<v?".indexOf(c))<0?d:q>3?t[p]!=0?-~d%3:d:q,p+=c==91?1:c==93?M-1:0,t[p%=M]-=c>42&c<46?c-44:0,System.out.print(c==46?(char)t[p]:""),y+=d%2-d%3%2*2,x+=3%-~d-d-~d%2)if((c=x<l&x>=m[y].length?0:m[y][x])==44&I<i.length)t[p]=i[I++];}
  5.  
  6. ;
  7.  
  8. public static void main(String[]a){
  9. test("v >]++]+++]+++]+[[[[-v\n"+
  10. "v >[v\n"+
  11. "v >]++++>?]+]+]-]]+>?[ -v\n"+
  12. ">++++++++>?]].]- --.+++++++ .. + ++. ]].[-.[.+++.------.--------.]]+.]++.\n"+
  13. " ^ <\n"+
  14. " ^ <\n"+
  15. " ^ <");
  16. test("v >-v\n"+
  17. "v >.>?, v\n"+
  18. ">,>?\n"+
  19. " ^ <\n"+
  20. " ^ <", "This is a test");
  21. test("v >-[v\n"+
  22. "v >->?]] +[v\n"+
  23. "v Some >-[++++]v\n"+
  24. "v rubbish >-[[. +]]v\n"+
  25. "v text! >-v\n"+
  26. "v >-]]++++>?[>?++++ +++ +++.>?[ v\n"+
  27. ">]->?] -]+ ++ +++>?\n"+
  28. " ^ <\n"+
  29. " ^ <\n"+
  30. " ^ <\n"+
  31. " ^ <\n"+
  32. " ^ <\n"+
  33. " ^ <");
  34. }
  35.  
  36. static void test(String program){
  37. test(program, "");
  38. }
  39.  
  40. static void test(String program, String inputs){
  41. System.out.println("2fuck program: ");
  42. System.out.println(program);
  43. System.out.println("Inputs: "+inputs);
  44. System.out.println("Output: ");
  45. try{f.apply(program.lines().map(String::getBytes).toArray(byte[][]::new)).accept(inputs.getBytes());}
  46. catch(ArrayIndexOutOfBoundsException e){System.err.println("Stopped with error: "+e);}
  47. System.out.println("\n"+"_".repeat(100)+"\n");
  48. }
  49. }
Success #stdin #stdout #stderr 0.22s 53576KB
stdin
Standard input is empty
stdout
2fuck program: 
v                >]++]+++]+++]+[[[[-v
v                           >[v
v         >]++++>?]+]+]-]]+>?[ -v
>++++++++>?]].]- --.+++++++ .. + ++. ]].[-.[.+++.------.--------.]]+.]++.
         ^                      <
                           ^  <
                ^                   <
Inputs: 
Output: 
Hello World!

____________________________________________________________________________________________________

2fuck program: 
v     >-v
v  >.>?, v
>,>?
  ^      <
     ^  <
Inputs: This is a test
Output: 
This is a test
____________________________________________________________________________________________________

2fuck program: 
v      >-[v
v   >->?]] +[v
v    Some                  >-[++++]v
v    rubbish                  >-[[. +]]v
v    text!                                   >-v
v                 >-]]++++>?[>?++++ +++ +++.>?[ v
>]->?] -]+ ++ +++>?
                 ^                              <
                                            ^  <
                             ^         <
                          ^        <
   ^         <
      ^   <
Inputs: 
Output: 
 !"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~

____________________________________________________________________________________________________

stderr
Stopped with error: java.lang.ArrayIndexOutOfBoundsException: Index 73 out of bounds for length 73
Stopped with error: java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 4
Stopped with error: java.lang.ArrayIndexOutOfBoundsException: Index 49 out of bounds for length 19