diff options
author | Ben Harris <ben@tilde.team> | 2019-12-11 17:58:48 -0500 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2019-12-11 17:58:48 -0500 |
commit | db981bdfefe64149c60dd11f96eb03dc1ac93321 (patch) | |
tree | b234df0de4dd3e2b1dc135995415542c99dbc29d /Day11.cs | |
parent | 6d22bf07fcb8781ea52d04ca70784aeef6fed5fa (diff) |
day 11 in progress
Diffstat (limited to 'Day11.cs')
-rw-r--r-- | Day11.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Day11.cs b/Day11.cs new file mode 100644 index 0000000..1c1e270 --- /dev/null +++ b/Day11.cs @@ -0,0 +1,75 @@ +using aoc2019.lib; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; + +namespace aoc2019 +{ + internal class Day11 : Day + { + public override int DayNumber => 11; + + private IntCodeVM vm; + List<List<bool>> paintmap; + long x, y; + Direction heading; + + public Day11() + { + vm = new IntCodeVM(Input.First()); + paintmap = new List<List<bool>>(); + x = 0; y = 0; + heading = Direction.Up; + } + + enum Direction + { + Up, Down, Left, Right + } + + private (long, long) DxDy() + { + return heading switch + { + Direction.Up => (0, 1), + Direction.Down => (0, -1), + Direction.Left => (-1, 0), + Direction.Right => (1, 0) + }; + } + + private void Turn(long direction) + { + switch (heading) + { + case Direction.Up: heading = direction == 0 ? Direction.Left : Direction.Right; break; + case Direction.Down: heading = direction == 0 ? Direction.Right : Direction.Left; break; + case Direction.Left: heading = direction == 0 ? Direction.Down : Direction.Up; break; + case Direction.Right: heading = direction == 0 ? Direction.Up : Direction.Down; break; + } + } + + public override string Part1() + { + vm.Reset(); + vm.Run(); + var output = vm.output.ToList(); + long dx, dy; + for (var i = 0; i < output.Count; i += 2) + { + long color = output[i]; + Turn(output[i + 1]); + paintmap[x][y] = color == 0; + (dx, dy) = DxDy(); + x += dx; y += dy; + } + return $"{paintmap.Count(x => x != null)}"; + } + + public override string Part2() + { + return ""; + } + } +} |