import java.util.*;

public class SpringDroid
{
    public static final int MAX_INSTRUCTIONS = 15;

    public static final String INSTRUCTIONS = "instructions.txt";

    /*
     * We know that after the droid jumps it will land 4 tiles away.
     * Only safe to jump when D is solid or we go spinning into space!
     * Only jump when there's a hole in front of the droid, i.e., A, B or C is
     * a space.
     *
     * Jump if there is a hole on A or on B or on C and there is no hole on D.
     *
     * 'OR A J', //  J = A
     * 'AND B J', // J = A AND B
     * 'AND C J', // J = A AND B AND C
     * 'NOT T J', // J = !A OR !B OR !C
     * 'AND D J', // J = (!A OR !B OR !C) AND D
     * 'WALK'
     */

    public static void main (String[] args)
    {
        boolean debug = false;

        for (int i = 0; i < args.length; i++)
        {
            if ("-help".equals(args[i]))
            {
                System.out.println("Usage: [-debug] [-help]");

                System.exit(0);
            }

            if ("-debug".equals(args[i]))
                debug = true;
        }

        Vector<String> values = IntcodeUtil.readValues(INSTRUCTIONS);
        Intcode computer = new Intcode(values, debug);

        computer.setInputs("O", "R", " ", "A", " ", "J", "\n");
        computer.setInputs("A", "N", "D", " ", "B", " ", "J", "\n");
        computer.setInputs("A", "N", "D", " ", "C", " ", "J", "\n");
        computer.setInputs("N", "O", "T", " ", "T", " ", "J", "\n");
        computer.setInputs("A", "N", "D", " ", "D", " ", "J", "\n");
        computer.setInputs("W", "A", "L", "K", "\n");

        computer.executeProgram();

        System.out.println(computer.getOutput());
    }
}
@@ -1217,25 +1217,24 @@
 debug);%0A
-%0A
         
 computer
@@ -1229,63 +1229,63 @@
     
-computer.setInputs(%22O%22, %22R%22, %22 %22, %22A%22, %22 %22, %22J%22, %22%5Cn%22);
+List%3CString%3E program = List.of(%0A            %22OR A J%5Cn%22,
 %0A   
@@ -1293,68 +1293,74 @@
     
-computer.setInputs(%22A%22, %22N%22, %22D%22, %22 %22, %22B%22, %22 %22, %22J%22, %22%5Cn%22);
+    %22AND B J%5Cn%22,%0A            %22AND C J%5Cn%22,%0A            %22NOT T J%5Cn%22,
 %0A   
@@ -1368,77 +1368,66 @@
     
-computer.setInputs(%22A%22, %22N%22, %22D%22, %22 %22, %22C%22, %22 %22, %22J%22, %22%5Cn%22
+    %22AND D J%5Cn%22,%0A            %22WALK%5Cn%22%0A        
 );%0A
+%0A
         
 comp
@@ -1426,77 +1426,61 @@
     
-computer.setInputs(%22N%22, %22O%22, %22T%22, %22 %22, %22T%22, %22 %22, %22J%22, %22%5Cn%22
+Iterator%3CString%3E iter = program.iterator(
 );%0A
+%0A
         
 comp
@@ -1479,77 +1479,90 @@
     
-computer.setInputs(%22A%22, %22N%22, %22D%22, %22 %22, %22D%22, %22 %22, %22J%22, %22%5Cn%22);%0A
+while (iter.hasNext())%0A        %7B%0A            String str = iter.next();%0A%0A  
         
 comp
@@ -1549,32 +1549,34 @@
 t();%0A%0A          
+  
 computer.setInpu
@@ -1582,34 +1582,62 @@
 uts(
-%22W%22, %22A%22, %22L%22, %22K%22, %22%5Cn%22);
+IntcodeUtil.convertStringToASCIIArray(str));%0A        %7D
 %0A%0A  

Update SpringDroid.java