public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { var parameter1 = ReadData(data, data[offset++], parameterModes, 0); _parameterComputer.AdjustBase(parameter1); return(false); }
public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { var output = ReadData(data, data[offset++], parameterModes, 0); OutputQueue.Add(output); return(false); }
public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { var input = _input.Take(); var value = data[offset++]; WriteData(data, input, value, parameterModes, 0); return(false); }
public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { var parameter1 = ReadData(data, data[offset++], parameterModes, 0); var parameter2 = ReadData(data, data[offset++], parameterModes, 1); WriteData(data, parameter1 + parameter2, data[offset++], parameterModes, 2); return(false); }
public IIntCodeData Compute(IIntCodeData data) { var n = IntCodeValue.FromInt(0); while (!Compute(data, ref n)) { } return(data); }
public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { var parameter1 = ReadData(data, data[offset++], parameterModes, 0); var parameter2 = ReadData(data, data[offset++], parameterModes, 1); if (parameter1 == IntCodeValue.FromInt(0)) { offset = parameter2; } return(false); }
public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { var parameter1 = ReadData(data, data[offset++], parameterModes, 0); var parameter2 = ReadData(data, data[offset++], parameterModes, 1); var parsedParameter3 = data[offset++]; var value = IntCodeValue.FromInt(0); if (parameter1 < parameter2) { value = IntCodeValue.FromInt(1); } WriteData(data, value, parsedParameter3, parameterModes, 2); return(false); }
public IntCodeValue FetchParameter(IIntCodeData data, IntCodeValue parsedValue, int?parameterMode) { var paramModeOrDefault = GetParameterModeOrDefault(parameterMode); switch (paramModeOrDefault) { case PositionMode: return(data[parsedValue]); case ImmediateMode: return(parsedValue); case RelativeMode: return(data[_base + parsedValue]); default: throw new ArgumentException("Invalid parameter mode"); } }
public void WriteParameter(IIntCodeData data, IntCodeValue input, IntCodeValue parsedValue, int?parameterMode) { var paramModeOrDefault = GetParameterModeOrDefault(parameterMode); switch (paramModeOrDefault) { case PositionMode: data[parsedValue] = input; return; case ImmediateMode: throw new InvalidOperationException("Writing instructions can't have parameters in immediate mode."); case RelativeMode: data[_base + parsedValue] = input; return; default: throw new ArgumentException("Invalid parameter mode"); } }
private bool Compute(IIntCodeData data, ref IntCodeValue offset) { var parsedOpCode = data[offset].ToString(); var opCodeLength = parsedOpCode.Length < 2 ? parsedOpCode.Length : 2; var opcode = opCodeLength == parsedOpCode.Length ? IntCodeValue.Parse(parsedOpCode) : IntCodeValue.Parse(parsedOpCode.Substring(parsedOpCode.Length - opCodeLength, opCodeLength)); var parameterModes = parsedOpCode.Length <= 2 ? new int[0] : parsedOpCode .Substring(0, parsedOpCode.Length - opCodeLength) .Select(c => int.Parse(c.ToString())) .Reverse() .ToArray(); offset++; var cmd = _commands[opcode]; return(cmd.Process(data, parameterModes, ref offset)); }
public abstract bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset);
protected void WriteData(IIntCodeData data, IntCodeValue valueToBeWritten, IntCodeValue parsedParameterValue, int[] parameterModes, int parameterIndex) { _parameterComputer.WriteParameter(data, valueToBeWritten, parsedParameterValue, GetParameterMode(parameterModes, parameterIndex)); }
protected IntCodeValue ReadData(IIntCodeData data, IntCodeValue parsedParameterValue, int[] parameterModes, int parameterIndex) { return(_parameterComputer.FetchParameter(data, parsedParameterValue, GetParameterMode(parameterModes, parameterIndex))); }
public override bool Process(IIntCodeData data, int[] parameterModes, ref IntCodeValue offset) { return(true); }