public override async Task Part2() { var allPuzzleLines = PuzzleInput.Split("\r\n"); var length = allPuzzleLines.First().Length; var height = allPuzzleLines.Count(); var maxCoordinate = new Coordinate() { X = length, Y = height }; for (int verticalLine = 0; verticalLine < maxCoordinate.Y; verticalLine++) { for (int horizontalLine = 0; horizontalLine < maxCoordinate.X; horizontalLine++) { var drawing = allPuzzleLines[verticalLine][horizontalLine]; if (drawing == '#') { Astroids.Add(new Astroid(horizontalLine, verticalLine)); } } } foreach (var astroid in Astroids) { astroid.TryLookAtAstroids(Astroids.Where(x => x != astroid).ToList()); } var bestAstroid = Astroids.OrderByDescending(x => x.VisibleAstroids.Count).First(); ResultPart2 = bestAstroid.Vaporize200Astroids(); }
public override string Part2() { var coordinates = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(c => c.Split(new[] { "," }, StringSplitOptions.None)).Select((d, e) => new GridCoordinate() { xVal = Convert.ToInt32(d[0].Trim()), yVal = Convert.ToInt32(d[1].Trim()), Value = (char)(e + 65) }).ToHashSet(); //Create Grid GridStride = Test ? 10 : 400; var grid = new Coordinate[GridStride * GridStride]; Parallel.For(0, GridStride, (x) => { Parallel.For(0, GridStride, (y) => { var pixel = new Coordinate() { xVal = x, yVal = y }; pixel = GeTotalManhattenDistanceValue(pixel, coordinates); grid[x + (y * GridStride)] = pixel; }); }); Print(grid); return(grid.Where(x => x.Value == '#').Count().ToString()); }
public override string Part2() { var boxIDs = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(c => c.ToCharArray()).ToHashSet(); var numberOfMatchingChars = boxIDs.First().Count() - 1; var returnstring = string.Empty; Parallel.ForEach(boxIDs, (box, loopState) => Parallel.ForEach(boxIDs, (matchBox, loopState2) => { var boxIDBuilder = new StringBuilder(); if (matchBox != box) { for (int i = 0; i < box.Length; i++) { if (box[i] == matchBox[i]) { boxIDBuilder.Append(box[i]); } } if (boxIDBuilder.Length == numberOfMatchingChars) { lock (lockLoop) { returnstring = boxIDBuilder.ToString(); loopState.Stop(); loopState2.Stop(); } } } boxIDBuilder.Clear(); })); return(returnstring); }
public override async Task Part1() { var puzzleinput1 = PuzzleInput.Split("\r\n"); Reactions = puzzleinput1.Select(x => new Reaction(x.Split("=>"))).ToList(); var fuelReaction = Reactions.Where(x => x.FuelMaterial() != null).FirstOrDefault(); var foundOre = false; var tree = RecursiveFunction(fuelReaction); var reactions = new List <Reaction>(); var flatlist = Traverse(tree); var inputDic = new Dictionary <string, int>(); var flatlistWithoutORE = flatlist.Where(x => x.InputMaterials.FirstOrDefault().Type != "ORE").ToList(); var flatlistORE = flatlist.Where(x => x.InputMaterials.FirstOrDefault().Type == "ORE").Distinct().ToList();; foreach (var item in flatlistWithoutORE) { var output = item.OutputMaterials.FirstOrDefault(); var inputMaterial = item.InputMaterials; int amount; var amountNeededAlready = inputDic.TryGetValue(output.Type, out amount); if (amount == 0) { amount = 1; } amount = output.Quantity * amount; foreach (var input in inputMaterial) { for (int i = 0; i < amount; i++) { if (!inputDic.TryAdd(input.Type, input.Quantity)) { inputDic[input.Type] += input.Quantity; } } } } var totalOREAmount = 0d; foreach (var oreReaction in flatlistORE) { var output = oreReaction.OutputMaterials.FirstOrDefault(); var type = output.Type; var howmanyIsNeeded = inputDic[type]; var reactionMultiply = Math.Ceiling((double)howmanyIsNeeded / (double)output.Quantity); var inputOre = oreReaction.InputMaterials.FirstOrDefault(); totalOREAmount += inputOre.Quantity * reactionMultiply; } var outputs = flatlistWithoutORE.Select(x => x.OutputMaterials); ResultPart1 = totalOREAmount.ToString(); }
public Day9(int day) : base(day) { Title = "Sensor Boost"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day9; ComputerMemoryInput = PuzzleInput.Split(',').Select(x => Convert.ToInt64(x)).ToList(); SolutionPart1 = "3497884671"; SolutionPart2 = "46470"; }
public Day2(int day) : base(day) { Title = "1202 Program Alarm"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day2; ComputerMemory = PuzzleInput.Split(',').Select(x => Convert.ToInt32(x)).ToList(); SolutionPart1 = "4484226"; SolutionPart2 = "5696"; }
public Day1(int day) : base(day) { Title = "The Tyranny of the Rocket Equation"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day1; Day1Modules = PuzzleInput.Split('\n').Select(x => Convert.ToDouble(x)); SolutionPart1 = "3325342"; SolutionPart2 = "4985158"; }
private long InvestigatePattern(Register register, long instructionPointer, bool startPrint = false) { InitializeOpcodeList(); var puzzleLines = PuzzleInput.Split("\r\n"); var boundRegister = Convert.ToInt32(puzzleLines.First().Replace("#ip ", "")); var samples = new List <Sample>(); foreach (var puzzleLine in puzzleLines.Skip(1)) { var instructions = puzzleLine.Split(" "); var opcode = GetOpcodeByName(instructions[0]); samples.Add(new Sample() { Instruction = new Instruction(opcode, instructions[1], instructions[2], instructions[3]) }); } var reg0 = (long)0; var difference = (long)0; for (int i = (int)instructionPointer; i < samples.Count(); i++) { samples[i].Before = register; samples[i].Before.Registers[boundRegister] = instructionPointer; samples[i].Instruction.Opcode(samples[i]); register = samples[i].After; difference = register.Registers[boundRegister] - instructionPointer; instructionPointer = register.Registers[boundRegister]; Print(i, samples[i], (int)instructionPointer); // if ((int)instructionPointer > 10) Print(samples[i], (int)instructionPointer); //if (startPrint) Print(i, samples[i], (int)instructionPointer); //reg0 = register.Registers[0]; //if (instructionPointer == 14) //{ // Print(i, samples[i], (int)instructionPointer); // startPrint = true; //} //if (instructionPointer == 33) //{ // startPrint = true; // Print(samples[i], (int)instructionPointer); //} instructionPointer++; if (instructionPointer >= samples.Count()) { reg0 = samples[i].After.Registers[0]; break; } i = i + (int)difference; } return(reg0); }
public Day13(int day) : base(day) { Title = "Care Package"; TestInput = ""; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day13; ComputerMemoryInput = PuzzleInput.Split(',').Select(x => Convert.ToInt64(x)).ToList(); SolutionPart1 = "412"; SolutionPart2 = "20940"; }
public Day4(int day) : base(day) { Title = "Secure Container"; //TestInput = "112233-670283"; //152085-670283 PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day4; Day2Integers = PuzzleInput.Split(',').Cast <int>(); SolutionPart1 = ""; SolutionPart2 = ""; }
public Day99(int day) : base(day) { Title = ""; TestInput = ""; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day1; Day2Integers = PuzzleInput.Split(',').Cast <int>(); SolutionPart1 = ""; SolutionPart2 = ""; }
public override string Part1() { //var testString = @"18 units each with 729 hit points (weak to fire; immune to cold, slashing) with an attack that does 8 radiation damage at initiative 10"; var game = new Game(); var digitRegex = new Regex(@"-?\d+"); var puzzleLines = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None); string type = string.Empty; var id = 0; foreach (var line in puzzleLines) { if (line.Length > 0 && line.Length < 50) { type = line; } else if (line.Length == 0) { //do nothing } else { var unitGroup = new UnitGroup(++id, type, line, 0); game.UnitGroups.Add(unitGroup); } } while (!game.GameOver) { game.UnitGroups.ForEach((c) => { c.UnitToAttack = null; c.UnitToDefend = null; }); //Choosing Phase var unitList = game.UnitGroups.OrderByDescending(c => c.EffectivePower()).ThenByDescending(c => c.Initiative).ToList(); for (int i = 0; i < unitList.Count(); i++) { var unit = game.UnitGroups.First(c => c.ID == unitList[i].ID); if (!unit.GameOver()) { unit.ChooseTarget(game.UnitGroups); } } var attackUnitList = game.UnitGroups.OrderByDescending(c => c.Initiative).ToList(); for (int i = 0; i < attackUnitList.Count(); i++) { var unit = game.UnitGroups.First(c => c.ID == attackUnitList[i].ID); if (!unit.GameOver()) { unit.Attack(); } } game.UnitGroups.RemoveAll(c => c.GameOver()); //Print(game.UnitGroups); } return(game.Part1()); }
public Day11(int day) : base(day) { Title = "Space Police"; //TestInput = "109,19,204,-34"; // TestInput = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day11; ComputerMemoryInput = PuzzleInput.Split(',').Select(x => Convert.ToInt64(x)).ToList(); SolutionPart1 = "2478"; SolutionPart2 = "hczrugaz"; }
public Day7(int day) : base(day) { Title = "Amplification Circuit"; // TestInput = @"3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54, //-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4, //53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day7; ComputerMemoryInput = PuzzleInput.Split(',').Select(x => Convert.ToInt32(x)).ToList(); SolutionPart1 = "21860"; SolutionPart2 = "2645740"; }
public override string Part1() { var digitRegex = new Regex(@"-?\d+"); var nanoBots = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(c => digitRegex.Matches(c)).Select(c => new Nanobot() { X = Convert.ToInt32(c[0].Value), Y = Convert.ToInt32(c[1].Value), Z = Convert.ToInt32(c[2].Value), Radius = Convert.ToInt32(c[3].Value) }).ToList(); var masterNanoBot = nanoBots.First(c => c.Radius == nanoBots.Max(d => d.Radius)); var countNanoBots = nanoBots.Where(c => IsManhattenValidRange(c, masterNanoBot)).Count(); return(countNanoBots.ToString()); }
public override string Part2() { InitializeOpcodeList(); var puzzleLines = PuzzleInput.Split("\r\n"); var boundRegister = Convert.ToInt32(puzzleLines.First().Replace("#ip ", "")); var samples = new List <Sample>(); foreach (var puzzleLine in puzzleLines.Skip(1)) { var instructions = puzzleLine.Split(" "); var opcode = GetOpcodeByName(instructions[0]); samples.Add(new Sample() { Instruction = new Instruction(opcode, instructions[1], instructions[2], instructions[3]) }); } Register register = new Register(0, 0, 0, 0, 0, 0); var instructionPointer = (long)0; var reg0 = (long)0; var difference = (long)0; var allVals = new HashSet <long>(); for (int i = 0; i < samples.Count(); i++) { samples[i].Before = register; samples[i].Before.Registers[boundRegister] = instructionPointer; samples[i].Instruction.Opcode(samples[i]); if (samples[i].Instruction.Opcode.Method.Name == "Eqrr") { var val = samples[i].After.Registers[3]; if (allVals.Contains(val)) { break; } allVals.Add(val); } register = samples[i].After; difference = register.Registers[boundRegister] - instructionPointer; instructionPointer = register.Registers[boundRegister]; instructionPointer++; if (instructionPointer >= samples.Count()) { reg0 = register.Registers[0]; break; } i = i + (int)difference; } return(allVals.Last().ToString()); }
public override string Part2() { NodeData = PuzzleInput.Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(c => Convert.ToInt32(c)).ToList(); var rootNode = new Node(); CreateChildNodes(rootNode); metaDataSum = GetNodeValueByMetaData(rootNode); if (Test) { Print(rootNode); } return(metaDataSum.ToString()); }
public Day3(int day) : base(day) { Title = "Crossed Wires"; // TestInput = "R8,U5,L5,D3\n" + "U7,R6,D4,L4"; // TestInput = "R75,D30,R83,U83,L12,D49,R71,U7,L72\nU62,R66,U55,R34,D71,R55,D58,R83"; // TestInput = @"R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 //U98,R91,D20,R16,D67,R40,U7,R15,U6,R7"; //TestInput = "R8,U5,L5,D3\n" + "U1,R1,D1,L1"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day3; Day3Wires = PuzzleInput.Split('\n'); SolutionPart1 = "896"; SolutionPart2 = "16524"; }
public override string Part1() { var potState = new StringBuilder(); var potStateZeroIndex = 5; if (Test) { potState.Append(".....#..#.#..##......###...###....."); } else { potState.Append(".....#.#..#..###.###.#..###.#####...########.#...#####...##.#....#.####.#.#..#..#.#..###...#..#.#....##....."); }; var splitRegex = new Regex("[=>]"); var combinations = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Split("=>")).ToDictionary(a => a[0].Trim(), b => b[1].Trim().First()); //new Dictionary<char[], char>() { var lookMargin = 2; for (int generation = 0; generation < 20; generation++) { Print(potState, potStateZeroIndex, generation); var referenceState = potState.ToString(); potState.Clear(); potState.Append("..."); for (int potIndex = lookMargin; potIndex < referenceState.Length - lookMargin; potIndex++) { var potPattern = referenceState.Substring(potIndex - lookMargin, 5); if (combinations.TryGetValue(potPattern, out char check)) { potState.Append(check); } else { potState.Append('.'); } } potState.Append("..."); potStateZeroIndex++; } var count = 0; for (int potIndex = 0; potIndex < potState.Length; potIndex++) { count += potState[potIndex] == '#' ? potIndex - potStateZeroIndex : 0; } return(count.ToString()); }
public Day5(int day) : base(day) { Title = "Sunny with a Chance of Asteroids"; // TestInput = @"3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, //1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, //999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99"; // TestInput = @"3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, //1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, //999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day5; ComputerMemoryInput = PuzzleInput.Split(',').Select(x => Convert.ToInt64(x)).ToList(); SolutionPart1 = "7566643"; SolutionPart2 = "9265694"; }
public override string Part1() { var strideX = PuzzleInput.Substring(0, PuzzleInput.IndexOf("\r\n")).Length; var strideY = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Count(); var yVal = 0; var acres = new int[strideX, strideY]; foreach (var puzzleAcre in PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList()) { var x = 0; foreach (var character in puzzleAcre) { acres[x, yVal] = character; x++; } yVal++; } if (Test) { Print(acres); } var minutes = 10; for (int i = 0; i < minutes; i++) { int[,] newAcres = acres.Clone() as int[, ]; for (int y = 0; y < acres.GetLength(1); y++) { for (int x = 0; x < acres.GetLength(0); x++) { newAcres[x, y] = (int)GetNewAcreType(x, y, acres); } } acres = newAcres; if (Test) { Print(acres); } } //Count wooded * lumberyars return(LumberResourcesAnswer(acres)); }
public override string Part2() { var regex = new Regex(@"\<(.*?)\>"); var points = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).AsParallel() .Select(c => regex.Matches(c)).Select((puzzle) => new Point(puzzle)).AsParallel().ToHashSet(); var seconds = 0; while (true) { seconds++; points.AsParallel().ForAll(point => point.Move()); if (!string.IsNullOrEmpty(GetGridResult(points))) { break; } } return(seconds.ToString()); }
public override string Part1() { var regex = new Regex(@"\<(.*?)\>"); var points = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).AsParallel() .Select(c => regex.Matches(c)).Select((puzzle) => new Point(puzzle)).AsParallel().ToHashSet(); var returnVal = string.Empty; while (true) { points.AsParallel().ForAll(point => point.Move()); returnVal = GetGridResult(points, true); if (returnVal != null) { break; } } //TODO Use OCR for .NET CORE when available return(returnVal); }
public override string Part2() { instructions = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(c => new char[2] { c.Skip(5).Take(1).First(), c.Skip(36).Take(1).First() }).ToList(); allChars = instructions.Select(c => c[0]).Union(instructions.Select(c => c[1])).Distinct().OrderBy(c => c).Select((d) => new InstuctionLetter { Letter = d, Seconds = d - (Test ? 64 : 4) }).ToList(); var seconds = 0; while (allChars.Any(c => !c.Done)) { //Set Available letter properties SetAvailablePropetyToAllAvailableLetters(); foreach (var letter in allChars.OrderBy(o => o.Letter).Where(c => !c.Done && c.Available && !c.InProcess && !c.WorkerDone)) { var worker = workers.Where(c => !c.Working).FirstOrDefault(); if (worker != null) { worker.ProcessAvailables(letter); } } //Let the Elves do their work workers.ForEach(c => c.Work()); if (Test) { Debug.WriteLine(string.Format("{0} AFTER WORK DONE:{1} PROCESS:{2}", seconds, new string(allChars.Where(c => c.Done).OrderBy(c => c.Order).Select(c => c.Letter).ToArray()), new string(allChars.Where(c => c.InProcess).OrderBy(c => c.Order).Select(c => c.Letter).ToArray()))); foreach (var myChar in allChars.OrderBy(o => o.Letter).Where(c => c.Done && c.Order == 0)) { myChar.Order = allChars.Max(c => c.Order) + 1; } } seconds++; } return(seconds.ToString()); }
public override string Part2() { var FoundFrequencies = new HashSet <int>(); var frequencies = PuzzleInput.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).Select(c => Convert.ToInt32(c)); var total = 0; while (true) { foreach (var frequency in frequencies) { total += frequency; if (FoundFrequencies.Contains(total)) { return(total.ToString()); } else { FoundFrequencies.Add(total); } } } }
public override string Part1() { instructions = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(c => new char[2] { c.Skip(5).Take(1).First(), c.Skip(36).Take(1).First() }).ToList(); var allChars = instructions.Select(c => c[0]).Union(instructions.Select(c => c[1])).Distinct().OrderBy(c => c).ToList(); while (allChars.Count() > 0) { foreach (var letter in allChars) { var avail = ProcessAvailables(letter); if (avail) { allChars.Remove(letter); break; } } } var charOrder = new string(orderedInstructions.ToArray()); return(charOrder); }
public override string Part1() { var boxIDs = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(c => c.ToCharArray()).ToHashSet(); var countMultiples = new int[2]; foreach (var box in boxIDs) { (bool, bool)multiple = (false, false); foreach (var letter in box.Distinct()) { var countChar = box.Count(c => c == letter); if (countChar == 3) { multiple.Item2 = true; } else if (countChar == 2) { multiple.Item1 = true; } if (multiple.Item1 && multiple.Item2) { break; } } if (multiple.Item1) { countMultiples[0] += 1; } if (multiple.Item2) { countMultiples[1] += 1; } } return((countMultiples[0] * countMultiples[1]).ToString()); }
public Day6(int day) : base(day) { Title = "Universal Orbit Map"; // TestInput = @"COM)B //B)C //C)D //D)E //E)F //B)G //G)H //D)I //E)J //J)K //K)L //K)YOU //I)SAN"; PuzzleInput = !string.IsNullOrEmpty(TestInput) ? TestInput : Resources.Day6; Day6OrbitList = PuzzleInput.Split("\r\n").Select(x => new Orbit() { PlanetFrom = x.Substring(0, x.IndexOf(')')), PlanetTo = x.Substring(x.IndexOf(')') + 1) }).ToList(); SolutionPart1 = "227612"; SolutionPart2 = ""; }
public override string Part1() { //PuzzleInput = @"0,0,0,0 // 3,0,0,0 // 0,3,0,0 // 0,0,3,0 // 0,0,0,3 // 0,0,0,6 // 9,0,0,0 //6,0,0,0 // 12,0,0,0"; //PuzzleInput = @"-1,2,2,0 //0,0,2,-2 //0,0,0,-2 //-1,2,0,0 //-2,-2,-2,2 //3,0,2,-1 //-1,3,2,2 //-1,0,-1,0 //0,2,1,-2 //3,0,0,0"; // PuzzleInput = @"1,-1,0,1 // 2,0,-1,0 //3,2,-1,0 //0,0,3,1 //0,0,-1,-1 //2,3,-2,0 //-2,2,0,0 //2,-2,0,-1 //1,-1,0,-1 //3,2,0,2"; //PuzzleInput = @"1,-1,-1,-2 //-2,-2,0,1 //0,2,1,3 //-2,3,-2,1 //0,2,3,-2 //-1,-1,1,-2 //0,-2,-1,0 //-2,2,3,-1 //1,2,2,0 //-1,-2,0,-2"; var constellationPoints = PuzzleInput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(d => d.Split(',')).Select((e, index) => new ConstellationPoint(index, e[0], e[1], e[2], e[3])).ToList(); List <List <ConstellationPoint> > constellations = new List <List <ConstellationPoint> >(); var constellationPointsScrapList = new List <ConstellationPoint>(); constellationPointsScrapList.AddRange(constellationPoints); //Initialize constellation var constellation = new List <ConstellationPoint>(); constellation.Add(constellationPoints[0]); //Remove from scraplist by ID constellationPointsScrapList.RemoveAll(c => constellation.Select(d => d.Index).Contains(c.Index)); var buildConstellation = true; while (buildConstellation) { var constellationGrewLarger = false; foreach (var constellationPointFromScrapList in constellationPointsScrapList) { var constellationPoint = constellationPoints.First(c => c.Index == constellationPointFromScrapList.Index); if (constellationPoint.BelongsToConstellation(constellation)) { constellation.Add(constellationPoint); constellationGrewLarger = true; } } if (constellationGrewLarger) { constellationPointsScrapList.RemoveAll(c => constellation.Select(d => d.Index).Contains(c.Index)); } else { constellationPointsScrapList.RemoveAll(c => constellation.Select(d => d.Index).Contains(c.Index)); constellations.Add(constellation); if (constellationPointsScrapList.Count() == 0) { buildConstellation = false; break; } constellation = new List <ConstellationPoint>() { constellationPoints.First(c => c.Index == constellationPointsScrapList.First().Index) }; constellationPointsScrapList.RemoveAll(c => constellation.Select(d => d.Index).Contains(c.Index)); } } var amountConstellations = constellations.Count(); return(""); }
public override async Task Part2() { var computers = Enumerable.Range(0, 50).ToList().Select(x => new IntCodeComputer(PuzzleInput.Split(',').Select(x => Convert.ToInt64(x)).ToList(), x)).ToList(); var queue = new ConcurrentDictionary <long, Queue <Packet> >(); var idleStatuss = new ConcurrentDictionary <long, bool>(); CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; var runAll = new List <Task <long?> >(); computers.ForEach(computer => runAll.Add(Task.Run(() => computer.RunTillOutputWithIdleStatus(queue, idleStatuss, tokenSource), token))); await Task.WhenAll(runAll); ResultPart2 = runAll.FirstOrDefault(x => x.Result.HasValue).Result.ToString(); }