public string Part2() { var vm = new Vm(_instructions); vm.AddInput(2); vm.Run(); return(string.Join(',', vm.Output)); //return vm.MemAccess(0).ToString(); }
public string Part1() { var painted = new HashSet <(int, int)>(); var white = new HashSet <(int, int)>(); var position = (0, 0); var direction = (0, 1); var vm = new Vm(_instructions); //vm.AddInput(1); do { var input = white.Contains(position) ? 1 : 0; vm.AddInput(input); vm.Run(); var color = vm.Output[^ 2];
public string Part2() { var vm = new Vm(_instructions); vm.MemSet(0, 2); // Start the field vm.Run(); var partitions = vm.Output.Partition(3); var tiles = new Dictionary <(BigInteger, BigInteger), BigInteger>(); var score = 0; foreach (var p in partitions) { var key = (p[0], p[1]); var val = p[2]; if (key == (-1, 0)) { score = int.Parse(val.ToString()); continue; } if (tiles.ContainsKey(key)) { tiles[key] = val; } else { tiles.Add(key, val); } } vm.DeleteOutput(); do { partitions = vm.Output.Partition(3); foreach (var p in partitions) { var key = (p[0], p[1]); var val = p[2]; if (key == (-1, 0)) { score = int.Parse(val.ToString()); continue; } if (tiles.ContainsKey(key)) { tiles[key] = val; } else { tiles.Add(key, val); } } vm.DeleteOutput(); var ball = tiles.Where(x => x.Value == 4).First().Key; var paddle = tiles.Where(x => x.Value == 3).First().Key; var dir = ball.Item1.CompareTo(paddle.Item1); vm.AddInput(dir); vm.Run(); } while (vm.Running); return(vm.LastOutput().ToString()); }