From db981bdfefe64149c60dd11f96eb03dc1ac93321 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 11 Dec 2019 17:58:48 -0500 Subject: day 11 in progress --- Day11.cs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Day11.cs (limited to 'Day11.cs') 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> paintmap; + long x, y; + Direction heading; + + public Day11() + { + vm = new IntCodeVM(Input.First()); + paintmap = new List>(); + 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 ""; + } + } +} -- cgit 1.4.1