<commit_before>import java.io.*;
import java.util.*;

public class Intcode
{
    public static final String DELIMITER = ",";
    public static final String INITIALISED_MEMORY = "0";

    public Intcode (Vector<String> values, boolean debug)
    {
        this(values, null, debug);
    }

    public Intcode (Vector<String> values, String initialInput, boolean debug)
    {
        _debug = debug;
        _instructionPointer = 0;
        _output = new Vector<String>();
        _memory = new Vector<String>(values);
        _input = new Vector<String>();
        
        if (initialInput != null)  // cannot have null as a valid input!
            _input.add(initialInput);

        _status = Status.CREATED;
        _relativeBase = 0;
    }

    public final boolean hasHalted ()
    {
        return (_status == Status.HALTED);
    }

    public final boolean hasPaused ()
    {
        return (_status == Status.PAUSED);
    }

    public final boolean waitingForInput ()
    {
        return (_status == Status.WAITING_FOR_INPUT);
    }

    public final int status ()
    {
        return _status;
    }

    public final boolean hasOutput ()
    {
        return (_output.size() > 0);
    }

    public final String getOutput ()
    {
        return _output.remove(0);
    }

    public final Vector<String> getOutputs ()
    {
        return _output;
    }

    public final void setInput (String input)
    {
        _input.add(input);
    }

    public void setInputs (String... input)
    {
        Arrays.stream(input).forEach(n -> setInput(n));
    }

    public final String getInput ()
    {
        try
        {
            return _input.get(0);
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public final Vector<String> getInputs ()
    {
        return _input;
    }

    public final String consumeInput ()
    {
        try
        {
            return _input.remove(0);
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public final void changeInstruction (int entry, String value)
    {
        _memory.setElementAt(value, entry);
    }

    /**
     * Execute all the commands given, only returning when paused or halted.
     * 
     * @return the current status.
     */

    public int executeProgram ()
    {
        while (!hasHalted())
        {
            singleStepExecution();  // assume input only needed once!
        }

        return _status;
    }

    /**
     * Execute until input required.
     * 
     * @return the current status.
     */

    public int executeUntilInput ()
    {
        do
        {
            singleStepExecution();
        }
        while (!waitingForInput());

        return _status;
    }

    /**
     * Execute one instruction at a time. If input is required and none is provided
     * then change status and pause anyway.
     * 
     * @return the current status.
     */

    public int singleStepExecution ()
    {
        if (hasHalted())
        {
            if (_debug)
                System.out.println("Intcode computer has halted!");

            return _status;
        }

        if (_debug)
            System.out.println("Intcode input <"+getInput()+"> and instruction pointer: "+_instructionPointer);

        String str = getOpcode(_memory.elementAt(_instructionPointer));
        int opcode = Integer.valueOf(str);
        int[] modes = ParameterMode.getModes(_memory.elementAt(_instructionPointer));


        if (_debug)
        {
            System.out.println("\nWorking on element "+_instructionPointer+" which is command "+Instructions.commandToString(opcode)+
                                    " ("+opcode+")"+" with parameter modes ...");

            ParameterMode.printModes(modes);
        }<commit_msg>Update Intcode.java<commit_after>import java.io.*;
import java.util.*;

public class Intcode
{
    public static final String DELIMITER = ",";
    public static final String INITIALISED_MEMORY = "0";

    public Intcode (Vector<String> values, boolean debug)
    {
        this(values, null, debug);
    }

    public Intcode (Vector<String> values, String initialInput, boolean debug)
    {
        _debug = debug;
        _instructionPointer = 0;
        _output = new Vector<String>();
        _memory = new Vector<String>(values);
        _input = new Vector<String>();
        
        if (initialInput != null)  // cannot have null as a valid input!
            _input.add(initialInput);

        _status = Status.CREATED;
        _relativeBase = 0;
    }

    public final boolean hasHalted ()
    {
        return (_status == Status.HALTED);
    }

    public final boolean hasPaused ()
    {
        return (_status == Status.PAUSED);
    }

    public final boolean waitingForInput ()
    {
        return (_status == Status.WAITING_FOR_INPUT);
    }

    public final int status ()
    {
        return _status;
    }

    public final boolean hasOutput ()
    {
        return (_output.size() > 0);
    }

    public final String getOutput ()
    {
        return _output.remove(0);
    }

    public final Vector<String> getOutputs ()
    {
        return _output;
    }

    public final void setInput (String input)
    {
        _input.add(input);
    }

    public void setInputs (String... input)
    {
        Arrays.stream(input).forEach(n -> setInput(n));
    }

    public final String getInput ()
    {
        try
        {
            return _input.get(0);
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public final Vector<String> getInputs ()
    {
        return _input;
    }

    public final String consumeInput ()
    {
        try
        {
            return _input.remove(0);
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public final void changeInstruction (int entry, String value)
    {
        _memory.setElementAt(value, entry);
    }

    /**
     * Execute all the commands given, only returning when paused or halted.
     * 
     * @return the current status.
     */

    public int executeProgram ()
    {
        while (!hasHalted())
        {
            singleStepExecution();  // assume input only needed once!
        }

        return _status;
    }

    /**
     * Execute until input required.
     * 
     * @return the current status.
     */

    public int executeUntilInput ()
    {
        do
        {
            singleStepExecution();
        }
        while (!waitingForInput());

        return _status;
    }

    /**
     * Execute one instruction at a time. If input is required and none is provided
     * then change status and pause anyway.
     * 
     * @return the current status.
     */

    public int singleStepExecution ()
    {
        if (hasHalted())
        {
            if (_debug)
                System.out.println("Intcode computer has halted!");

            return _status;
        }

        if (_debug)
            System.out.println("Intcode input <"+getInput()+"> and instruction pointer: "+_instructionPointer);

        String str = getOpcode(_memory.elementAt(_instructionPointer));
        int opcode = Integer.valueOf(str);
        int[] modes = ParameterMode.getModes(_memory.elementAt(_instructionPointer));

        System.out.println("instruction "+_memory.elementAt(_instructionPointer));
        System.out.println("base "+_relativeBase);

        if (_debug)
        {
            System.out.println("\nWorking on element "+_instructionPointer+" which is command "+Instructions.commandToString(opcode)+
                                    " ("+opcode+")"+" with parameter modes ...");

            ParameterMode.printModes(modes);
        }
{'fraction_non_alphanumeric': 0.10147172734314484, 'fraction_numerical': 0.0018073844564936742, 'mean_word_length': 1.7767025089605735, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5432449', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2056, 'n_words': 563}