public static int Run(int first, int second) { List <int> numbers = AdventUtils.ReadCommaIntList("Inputs/Day2Input.txt"); numbers[1] = first; numbers[2] = second; int currentPoint = 0; while (true) { if (numbers[currentPoint] == 99) { return(numbers[0]); } int instruction = numbers[currentPoint]; var value1 = numbers[currentPoint + 1]; var value2 = numbers[currentPoint + 2]; var position = numbers[currentPoint + 3]; if (instruction != 1 && instruction != 2) { throw new Exception("Uh Oh"); } numbers[position] = instruction == 1 ? numbers[value1] + numbers[value2] : numbers[value1] * numbers[value2]; currentPoint += 4; } }
public static int Run() { List <int> numbers = AdventUtils.ReadCommaIntList("Inputs/Day5Input.txt"); int location = 0; while (numbers[location] != 99) { (int, List <(bool, int)>)nextCode = ReadOpCode(numbers, location); RunOpCode(nextCode.Item1, nextCode.Item2, numbers, ref location); } return(0); }
static public int Run() { int maxValue = int.MinValue; List <int> instructions = AdventUtils.ReadCommaIntList("Inputs/Day7Input.txt"); List <int> opCodes = new List <int>() { 0, 1, 2, 3, 4 }; var things = opCodes.Permute(); foreach (var foo in things) { var thing = foo.GetEnumerator(); thing.MoveNext(); int output1 = IntCode.Run(new List <int>(instructions), new List <int>() { thing.Current, 0 }); thing.MoveNext(); int output2 = IntCode.Run(new List <int>(instructions), new List <int>() { thing.Current, output1 }); thing.MoveNext(); int output3 = IntCode.Run(new List <int>(instructions), new List <int>() { thing.Current, output2 }); thing.MoveNext(); int output4 = IntCode.Run(new List <int>(instructions), new List <int>() { thing.Current, output3 }); thing.MoveNext(); int output5 = IntCode.Run(new List <int>(instructions), new List <int>() { thing.Current, output4 }); maxValue = Math.Max(maxValue, output5); } return(maxValue); }
public static int Run() { // Is it going to be better to do this as obscure or as able to see? // See might be the easier option, we can do width to height ratio, then work out where that would intercept each row/column and // check for an asteroid there? // OR we could do it as the blocks? Where we know that whole numbers are required, except that is not true. List <(int, int)> asteroids = AdventUtils.ReadAsteroidMap("Inputs/Day10Input.txt"); (int, int)station = (26, 29); //(int, int) station = (11, 13); //double angle = Angle((11, 12), station); var removedCount = 0; while (removedCount < 200) { var current = asteroids.Where(x => CanSee(x, station, asteroids)).ToList(); current.Remove(station); var sorted = current.OrderBy(x => Angle(x, station)).ToList(); var item = sorted[199]; return(item.Item1 * 100 + item.Item2); } bool answer = CanSee((6, 0), (4, 2), asteroids); List <(int, (int, int))> seeCount = new List <(int, (int, int))>(); foreach (var item in asteroids) { int count = -1; foreach (var other in asteroids) { if (CanSee(item, other, asteroids)) { ++count; } } seeCount.Add((count, item)); } var location = seeCount.Where(y => y.Item1 == seeCount.Max(x => x.Item1)); return(0); }
public static int Run() { List <int> input = AdventUtils.ReadIntList("Inputs/Day8Input.txt"); List <List <List <int> > > layers = new List <List <List <int> > >(); // 25 wide by 6 tall int layersCount = input.Count / (25 * 6); int count = 0; for (int i = 0; i < layersCount; ++i) { List <List <int> > currentLayer = new List <List <int> >(); for (int j = 0; j < 6; ++j) { List <int> currentRow = new List <int>(); for (int k = 0; k < 25; ++k) { currentRow.Add(input[count]); ++count; } currentLayer.Add(currentRow); } layers.Add(currentLayer); } List <List <int> > finalPicture = new List <List <int> >(); for (int i = 0; i < 6; ++i) { List <int> values = new List <int>(); for (int j = 0; j < 25; ++j) { for (int k = 0; k < layers.Count; ++k) { if (layers[k][i][j] != 2) { values.Add(layers[k][i][j]); break; } if (k == layersCount - 1) { throw new ArgumentException("uh oh"); } } } finalPicture.Add(values); } foreach (var row in finalPicture) { foreach (var value in row) { if (value == 1) { Console.Write("*"); } else { Console.Write(" "); } } Console.Write("\n"); } return(0); }