<commit_before>package common;

import java.math.BigInteger;
import java.util.*;

public class IntcodeComputer {

    public final static int OPCODE_ADD = 1;
    public final static int OPCODE_MULTIPLY = 2;
    public final static int OPCODE_INPUT = 3;
    public final static int OPCODE_OUTPUT = 4;
    public final static int OPCODE_JUMP_IF_TRUE = 5;
    public final static int OPCODE_JUMP_IF_FALSE = 6;
    public final static int OPCODE_LESS_THAN = 7;
    public final static int OPCODE_EQUALS = 8;
    public final static int OPCODE_ADJUST_RELATIVE_BASE = 9;
    public final static int OPCODE_HALT = 99;

    protected int instructionPointer = 0;
    protected int relativeBase = 0;
    protected Map<Integer, BigInteger> positions;

    protected Queue<BigInteger> inputs;
    protected Queue<BigInteger> outputs;
    protected BigInteger lastOutput = null;

    protected boolean halted = false;

    protected boolean verbose = false;

    protected boolean interruptOnOutput = false;

    public class IntcodeException extends Exception {}

    public class UnknownOpcodeException extends IntcodeException {}

    public class InvalidImmediateException extends IntcodeException {}

    public class WaitingOnInputInterrupt extends IntcodeException {}

    public class OutputInterrupt extends IntcodeException {}

    public class UnknownParameterModeException extends IntcodeException {}

    public IntcodeComputer(int[] positions) {
        setup();
        setPositions(positions);
    }

    public IntcodeComputer(BigInteger[] positions) {
        setup();
        setPositions(positions);
    }

    protected void setup() {
        this.positions = new HashMap<>();
        inputs = new LinkedList<>();
        outputs = new LinkedList<>();
    }

    public static int[] buildInputPositions(String input) {
        String[] values = input.split(",");
        return Arrays.stream(values).mapToInt(Integer::parseInt).toArray();
    }

    public static BigInteger[] buildInputPositionsBigInteger(String input) {
        String[] values = input.split(",");
        BigInteger[] inputPositions = new BigInteger[values.length];
        for (int i = 0; i < values.length; i++) {
            inputPositions[i] = new BigInteger(values[i]);
        }
        return inputPositions;
    }

    public boolean isHalted() {
        return halted;
    }

    public void setVerbose(boolean verbose) {
        this.verbose = verbose;
    }

    public void pushOntoInputs(BigInteger input) {
        inputs.add(input);
    }

    public void pushOntoInputs(int input) {
        pushOntoInputs(BigInteger.valueOf(input));
    }

    public void pushOntoInputs(int[] inputs) {
        for (int input : inputs) {
            pushOntoInputs(input);
        }
    }

    public void pushOntoInputs(Queue<BigInteger> inputs) {
        for (BigInteger input : inputs) {
            pushOntoInputs(input);
        }
    }

    protected void setPositions(int[] positions) {
        BigInteger[] positionsBigInteger = (BigInteger[]) Arrays.stream(positions).mapToObj(BigInteger::valueOf).toArray();
        setPositions(positionsBigInteger);
    }

    protected void setPositions(BigInteger[] positions) {
        for (int i = 0; i < positions.length; i++) {
            this.positions.put(i, positions[i]);
        }
    }

    public int processDay02() throws IntcodeException {
        process();
        return outputs.peek().intValue();
    }

    public int processAndReturnLastOutput(int[] inputs) throws IntcodeException {
        process(inputs);
        return getLastOutput().intValue();
    }

    public Queue<BigInteger> process(int[] inputs) throws IntcodeException {
        pushOntoInputs(inputs);
        return process();
    }

    public BigInteger processWithFeedback(IntcodeComputer nextComputer) throws IntcodeException {
        interruptOnOutput = true;
        try {
            process();
        }
        catch (IntcodeComputer.WaitingOnInputInterrupt exception) {
            nextComputer.pushOntoInputs(outputs);
            outputs.clear();
            return null;
        }
        catch (OutputInterrupt exception) {
            nextComputer.pushOntoInputs(outputs);
            outputs.clear();
            return null;
        }
        return getLastOutput();
    }

    public Queue<BigInteger> process() throws IntcodeException {
        int opcode = getPositionValue().intValue();<commit_msg>IntcodeComputer support for `setInterruptOnOutput()`<commit_after>package common;

import java.math.BigInteger;
import java.util.*;

public class IntcodeComputer {

    public final static int OPCODE_ADD = 1;
    public final static int OPCODE_MULTIPLY = 2;
    public final static int OPCODE_INPUT = 3;
    public final static int OPCODE_OUTPUT = 4;
    public final static int OPCODE_JUMP_IF_TRUE = 5;
    public final static int OPCODE_JUMP_IF_FALSE = 6;
    public final static int OPCODE_LESS_THAN = 7;
    public final static int OPCODE_EQUALS = 8;
    public final static int OPCODE_ADJUST_RELATIVE_BASE = 9;
    public final static int OPCODE_HALT = 99;

    protected int instructionPointer = 0;
    protected int relativeBase = 0;
    protected Map<Integer, BigInteger> positions;

    protected Queue<BigInteger> inputs;
    protected Queue<BigInteger> outputs;
    protected BigInteger lastOutput = null;

    protected boolean halted = false;

    protected boolean verbose = false;

    protected boolean interruptOnOutput = false;

    public class IntcodeException extends Exception {}

    public class UnknownOpcodeException extends IntcodeException {}

    public class InvalidImmediateException extends IntcodeException {}

    public class WaitingOnInputInterrupt extends IntcodeException {}

    public class OutputInterrupt extends IntcodeException {}

    public class UnknownParameterModeException extends IntcodeException {}

    public IntcodeComputer(int[] positions) {
        setup();
        setPositions(positions);
    }

    public IntcodeComputer(BigInteger[] positions) {
        setup();
        setPositions(positions);
    }

    protected void setup() {
        this.positions = new HashMap<>();
        inputs = new LinkedList<>();
        outputs = new LinkedList<>();
    }

    public static int[] buildInputPositions(String input) {
        String[] values = input.split(",");
        return Arrays.stream(values).mapToInt(Integer::parseInt).toArray();
    }

    public static BigInteger[] buildInputPositionsBigInteger(String input) {
        String[] values = input.split(",");
        BigInteger[] inputPositions = new BigInteger[values.length];
        for (int i = 0; i < values.length; i++) {
            inputPositions[i] = new BigInteger(values[i]);
        }
        return inputPositions;
    }

    public boolean isHalted() {
        return halted;
    }

    public void setVerbose(boolean verbose) {
        this.verbose = verbose;
    }

    public void setInterruptOnOutput(boolean interruptOnOutput) {
        this.interruptOnOutput = interruptOnOutput;
    }

    public void pushOntoInputs(BigInteger input) {
        inputs.add(input);
    }

    public void pushOntoInputs(int input) {
        pushOntoInputs(BigInteger.valueOf(input));
    }

    public void pushOntoInputs(int[] inputs) {
        for (int input : inputs) {
            pushOntoInputs(input);
        }
    }

    public void pushOntoInputs(Queue<BigInteger> inputs) {
        for (BigInteger input : inputs) {
            pushOntoInputs(input);
        }
    }

    protected void setPositions(int[] positions) {
        BigInteger[] positionsBigInteger = (BigInteger[]) Arrays.stream(positions).mapToObj(BigInteger::valueOf).toArray();
        setPositions(positionsBigInteger);
    }

    protected void setPositions(BigInteger[] positions) {
        for (int i = 0; i < positions.length; i++) {
            this.positions.put(i, positions[i]);
        }
    }

    public int processDay02() throws IntcodeException {
        process();
        return outputs.peek().intValue();
    }

    public int processAndReturnLastOutput(int[] inputs) throws IntcodeException {
        process(inputs);
        return getLastOutput().intValue();
    }

    public Queue<BigInteger> process(int[] inputs) throws IntcodeException {
        pushOntoInputs(inputs);
        return process();
    }

    public BigInteger processWithFeedback(IntcodeComputer nextComputer) throws IntcodeException {
        setInterruptOnOutput(true);
        try {
            process();
        }
        catch (IntcodeComputer.WaitingOnInputInterrupt exception) {
            nextComputer.pushOntoInputs(outputs);
            outputs.clear();
            return null;
        }
        catch (OutputInterrupt exception) {
            nextComputer.pushOntoInputs(outputs);
            outputs.clear();
            return null;
        }
        return getLastOutput();
    }

    public Queue<BigInteger> process() throws IntcodeException {
        int opcode = getPositionValue().intValue();
{'fraction_non_alphanumeric': 0.0879096545615589, 'fraction_numerical': 0.0037643932683790967, 'mean_word_length': 2.8454661558109833, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3381087', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2392, 'n_words': 627}