import java.util.*;

public class AmplifierSeries
{
    public AmplifierSeries (Vector<String> permutations, boolean debug)
    {
        _permutations = permutations;
        _debug = debug;
        _amps = null;
    }

    public void initialiseAmplifiers (String[] commands)
    {
        for (int i = 0; i < ACS.NUMBER_OF_AMPLIFIERS; i++)
        {
            _amps[i] = new Amplifier(i, commands, _debug);
        }
    }

    public int maxThrusterSignal ()
    {
        int maxThrusterSignal = 0;
        int[] results = new int[ACS.NUMBER_OF_AMPLIFIERS];
        Enumeration<String> iter = _permutations.elements();

        while (iter.hasMoreElements())
        {
            String permutation = iter.nextElement();
            int[] phaseSetting = new int[permutation.length()];
            int loop = 0;
            boolean halted = false;

            for (int i = 0; i < permutation.length(); i++)
            {
                phaseSetting[i] = Character.getNumericValue(permutation.charAt(i));

                if (_debug)
                    System.out.println("Phase setting "+i+" is "+phaseSetting[i]);
            }

            while (!halted)
            {
                if (!_amps[0].halted())
                {
                    if (loop == 0)
                        results[0] = _amps[0].executeProgram(phaseSetting[0], 0);
                    else
                        results[0] = _amps[0].executeProgram(phaseSetting[0], results[4]);

                    if (_debug)
                        System.out.println("Amplifier 0 returned "+results[0]);
                }
                else
                {
                    if (_debug)
                        System.out.println("Amplifier 0 has already halted.");
                }

                if (!_amps[1].halted())
                {
                    results[1] = _amps[1].executeProgram(phaseSetting[1], results[0]);

                    if (_debug)
                        System.out.println("Amplifier 1 returned "+results[1]);
                }
                else
                {
                    if (_debug)
                        System.out.println("Amplifier 1 has already halted.");
                }

                if (!_amps[2].halted())
                {
                    results[2] = _amps[2].executeProgram(phaseSetting[2], results[1]);

                    if (_debug)
                        System.out.println("Amplifier 2 returned "+results[2]);
                }
                else
                {
                    if (_debug)
                        System.out.println("Amplifier 2 has already halted.");
                }

                if (!_amps[3].halted())
                {
                    results[3] = _amps[3].executeProgram(phaseSetting[3], results[2]);

                    if (_debug)
                        System.out.println("Amplifier 3 returned "+results[3]);
                }
                else
                {
                    if (_debug)
                        System.out.println("Amplifier 3 has already halted.");
                }

                if (!_amps[4].halted())
                {
                    results[4] = _amps[4].executeProgram(phaseSetting[4], results[3]);

                    if (_debug)
                        System.out.println("Amplifier 4 returned "+results[4]);

                    if (_amps[4].halted())
                        halted = true;
                }
                else
                {
                    if (_debug)
                        System.out.println("Amplifier 4 has already halted.");
                }

                // it's the last output from amp 4 we want, not every output.

                if (_amps[4].halted() && (results[4] > maxThrusterSignal))
                    maxThrusterSignal = results[4];
            }
        }

        if (_debug)
            System.out.println("Max thrusters: "+maxThrusterSignal);

        return maxThrusterSignal;
    }

    protected Vector<String> _permutations;
    protected boolean _debug;
    private Amplifier[] _amps = new Amplifier[ACS.NUMBER_OF_AMPLIFIERS];
}
@@ -269,32 +269,90 @@
 commands)%0A    %7B%0A
+        _amps = new Amplifier%5BACS.NUMBER_OF_AMPLIFIERS%5D;%0A%0A
         for (int

Update AmplifierSeries.java