diff --git a/Day11/Day11.cs b/Day11/Day11.cs index e80c5d3..a0b1b3f 100644 --- a/Day11/Day11.cs +++ b/Day11/Day11.cs @@ -14,6 +14,7 @@ namespace Advent var x = 0; var y = 0; var direction = 0; + var paintCount = 0; while (!robot.Halted) { @@ -21,11 +22,52 @@ namespace Advent var currentColor = panels.ContainsKey(key) ? panels[key] : 0; - var color = robot.Execute(0); - var turn = robot.Execute(0); + var color = robot.Execute(currentColor); + + if (color != currentColor && !panels.ContainsKey(key)) + paintCount++; panels[key] = color; + + var turn = robot.Execute(0); + + switch (turn) + { + case 0: + direction -= 90; + + if (direction < 0) + direction += 360; + + break; + + case 1: + direction += 90; + + if (direction >= 360) + direction -= 360; + + break; + } + + switch (direction) + { + case 0: + y++; + break; + case 90: + x++; + break; + case 180: + y--; + break; + case 270: + x--; + break; + } } + + Console.WriteLine(paintCount); } } } diff --git a/IntcodeComputer.cs b/IntcodeComputer.cs index 7380afa..2e4231e 100644 --- a/IntcodeComputer.cs +++ b/IntcodeComputer.cs @@ -96,9 +96,7 @@ namespace Advent _setPhase = true; - var writeValue = _memory[_instructionPointer + 1]; - - SetValue(inputValue, _memory[_instructionPointer + 3], mode3); + SetValue(inputValue, _memory[_instructionPointer + 1], mode1); _instructionPointer += 2;