public static int SolvePart1(string input) { var squaresUsed = 0; for (var i = 0; i < 128; i++) { var knotHash = Day10.SolvePart2($"{input}-{i}", 256); var binaryString = String.Join("", knotHash.Select(x => Convert.ToString(Convert.ToInt32(x.ToString(), 16), 2).PadLeft(4, '0'))); squaresUsed += binaryString.Replace("0", "").Length; } return(squaresUsed); }
private static string KnotHash(string input) { List <int> inputList = new List <int>(); foreach (char c in input) { inputList.Add(c); } inputList.AddRange(new int[] { 17, 31, 73, 47, 23 }); List <int> sparseHash = new List <int>(); for (int i = 0; i < 256; i++) { sparseHash.Add(i); } int currIndx = 0; int skipSize = 0; for (int j = 0; j < 64; ++j) { foreach (int i in inputList) { var temp = Day10.ReverseRange(sparseHash, currIndx, i); sparseHash = Day10.ReplaceRange(sparseHash, temp, currIndx, i); currIndx += i + skipSize; skipSize++; while (currIndx > sparseHash.Count) { currIndx -= sparseHash.Count; } } } List <int> denseHash = new List <int>(); for (int i = 0; i < 16; ++i) { int j = i * 16; denseHash.Add(sparseHash[j] ^ sparseHash[j + 1] ^ sparseHash[j + 2] ^ sparseHash[j + 3] ^ sparseHash[j + 4] ^ sparseHash[j + 5] ^ sparseHash[j + 6] ^ sparseHash[j + 7] ^ sparseHash[j + 8] ^ sparseHash[j + 9] ^ sparseHash[j + 10] ^ sparseHash[j + 11] ^ sparseHash[j + 12] ^ sparseHash[j + 13] ^ sparseHash[j + 14] ^ sparseHash[j + 15]); } string output = ""; foreach (int i in denseHash) { output += i.ToString("X2"); } return(output); }
static void Main(string[] args) { Console.WriteLine("Results:"); Day01.ShowResult(); Day02.ShowResult(); Day03.ShowResult(); Day04.ShowResult(); Day05.ShowResult(); Day06.ShowResult(); Day07.ShowResult(); Day08.ShowResult(); Day09.ShowResult(); Day10.ShowResult(); Console.ReadKey(); }
/// <summary> /// Build a 128-element array of 128-character binary strings for the knot hashes /// of the given input string from "input-0" to "input-127" /// </summary> /// <param name="input">Input string to hash</param> /// <returns>128x128 binary grid of the hashes</returns> private static string[] BuildMap(string input) { var hexMap = new Dictionary <char, string> { { '0', "0000" }, { '1', "0001" }, { '2', "0010" }, { '3', "0011" }, { '4', "0100" }, { '5', "0101" }, { '6', "0110" }, { '7', "0111" }, { '8', "1000" }, { '9', "1001" }, { 'a', "1010" }, { 'b', "1011" }, { 'c', "1100" }, { 'd', "1101" }, { 'e', "1110" }, { 'f', "1111" } }; var hasher = new Day10(); var hashes = Enumerable.Range(0, 128) .Select(i => $"{input}-{i}") .Select(hasher.Part2) .Select(hash => string.Join(string.Empty, hash.Select(c => hexMap[c]))) .ToArray(); return(hashes); }
public static int SolvePart2(string input) { var squares = new List <DiskSquare>(); for (var i = 0; i < 128; i++) { var knotHash = Day10.SolvePart2($"{input}-{i}", 256); var binaryString = String.Join("", knotHash.Select(x => Convert.ToString(Convert.ToInt32(x.ToString(), 16), 2).PadLeft(4, '0'))); for (int j = 0; j < binaryString.Length; j++) { squares.Add(new DiskSquare { Point = new Point(j, i), Used = binaryString[j] == '1' }); } } var currentRegionNumber = 0; foreach (var square in squares) { if (square.Used && square.RegionNumber == null) { var queue = new Queue <DiskSquare>(new [] { square }); while (queue.Count != 0) { var queueSquare = queue.Dequeue(); var neighbours = squares.Where(x => x.Used && Day3.CalculateManhattanDistance(queueSquare.Point, x.Point) == 1).ToArray(); var neighbourRegionNumber = neighbours.Where(x => x.RegionNumber.HasValue) .Select(x => x.RegionNumber).FirstOrDefault(); queueSquare.RegionNumber = neighbourRegionNumber ?? ++currentRegionNumber; foreach (var neighbour in neighbours.Where(x => !x.RegionNumber.HasValue)) { queue.Enqueue(neighbour); } } } } return(currentRegionNumber); }
public void Do() { var line = System.IO.File.ReadAllText("../../Day14.txt"); var occupiedSquares = 0; var size = 128; var grid = new int[size][]; for (var i = 0; i < 128; i++) { var resultHex = Day10.DenseHash(line + "-" + i); var resultInBinary = resultHex.Select(r => Convert.ToString(Convert.ToInt32(r.ToString(), 16), 2).PadLeft(4, '0')).Aggregate((a, next) => a + next); occupiedSquares += resultInBinary.Select(c => int.Parse(c.ToString())).Aggregate((prev, next) => prev += next); grid[i] = resultInBinary.Select(c => int.Parse(c.ToString())).ToArray(); } Console.WriteLine("Day14 Part1: result is " + occupiedSquares); Console.WriteLine("Day14 Part2: result is " + occupiedSquares); }
public static void TestAll() { try { Console.WriteLine("Running tests for 2018"); Verifier.Verify(435, Day01.Part1(), "day 1 part 1"); Verifier.Verify(245, Day01.Part2(), "day 1 part 2"); Verifier.Verify(6448, Day02.Part1(), "day 2 part 1"); Verifier.Verify(0, Day02.Part2(), "day 2 part 1"); Verifier.Verify(0, Day03.Part1(), "day 3 part 1"); Verifier.Verify(0, Day03.Part2(), "day 3 part 2"); Verifier.Verify(0, Day04.Part1(), "day 4 part 1"); Verifier.Verify(0, Day04.Part2(), "day 4 part 2"); Verifier.Verify(0, Day05.Part1(), "day 5 part 1"); Verifier.Verify(0, Day05.Part2(), "day 5 part 2"); Verifier.Verify(0, Day06.Part1(), "day 6 part 1"); Verifier.Verify(0, Day06.Part2(), "day 6 part 2"); Verifier.Verify(0, Day07.Part1(), "day 7 part 1"); Verifier.Verify(0, Day07.Part2(), "day 7 part 2"); Verifier.Verify(0, Day08.Part1(), "day 8 part 1"); Verifier.Verify(0, Day08.Part2(), "day 8 part 2"); Verifier.Verify(0, Day09.Part1(), "day 9 part 1"); Verifier.Verify(0, Day09.Part2(), "day 9 part 2"); Verifier.Verify(0, Day10.Part1(), "day 10 part 1"); Verifier.Verify(0, Day10.Part2(), "day 10 part 2"); Verifier.Verify(0, Day11.Part1(), "day 11 part 1"); Verifier.Verify(0, Day11.Part2(), "day 11 part 2"); Verifier.Verify(0, Day12.Part1(), "day 12 part 1"); Verifier.Verify(0, Day12.Part2(), "day 12 part 2"); Verifier.Verify(0, Day13.Part1(), "day 13 part 1"); Verifier.Verify(0, Day13.Part2(), "day 13 part 2"); Verifier.Verify(0, Day14.Part1(), "day 14 part 1"); Verifier.Verify(0, Day14.Part2(), "day 14 part 2"); Verifier.Verify(0, Day15.Part1(), "day 15 part 1"); Verifier.Verify(0, Day15.Part2(), "day 15 part 2"); Verifier.Verify(0, Day16.Part1(), "day 16 part 1"); Verifier.Verify(0, Day16.Part2(), "day 16 part 2"); Verifier.Verify(0, Day17.Part1(), "day 17 part 1"); Verifier.Verify(0, Day17.Part2(), "day 17 part 2"); Verifier.Verify(0, Day18.Part1(), "day 18 part 1"); Verifier.Verify(0, Day18.Part2(), "day 18 part 2"); Verifier.Verify(0, Day19.Part1(), "day 19 part 1"); Verifier.Verify(0, Day19.Part2(), "day 19 part 2"); Verifier.Verify(0, Day20.Part1(), "day 20 part 1"); Verifier.Verify(0, Day20.Part2(), "day 20 part 2"); Verifier.Verify(0, Day21.Part1(), "day 21 part 1"); Verifier.Verify(0, Day21.Part2(), "day 21 part 2"); Verifier.Verify(0, Day22.Part1(), "day 22 part 1"); Verifier.Verify(0, Day22.Part2(), "day 22 part 2"); Verifier.Verify(0, Day23.Part1(), "day 23 part 1"); Verifier.Verify(0, Day23.Part2(), "day 23 part 2"); Verifier.Verify(0, Day24.Part1(), "day 24 part 1"); Verifier.Verify(0, Day24.Part2(), "day 24 part 2"); Verifier.Verify(0, Day25.Part1(), "day 25 part 1"); Console.WriteLine("All tests for 2018 OK"); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void TestAll() { try { Console.WriteLine("Running tests for 2020"); Verifier.Verify(55776, Day01.Part1(0), "day 1 part 1"); Verifier.Verify(223162626, Day01.Part2(0), "day 1 part 2"); Verifier.Verify(622, Day02.Part1(0), "day 2 part 1"); Verifier.Verify(263, Day02.Part2(0), "day 2 part 1"); Verifier.Verify(159, Day03.Part1(0), "day 3 part 1"); Verifier.Verify(6419669520, Day03.Part2(0), "day 3 part 2"); Verifier.Verify(210, Day04.Part1(0), "day 4 part 1"); Verifier.Verify(131, Day04.Part2(0), "day 4 part 2"); Verifier.Verify(894, Day05.Part1(0), "day 5 part 1"); Verifier.Verify(579, Day05.Part2(0), "day 5 part 2"); Verifier.Verify(6530, Day06.Part1(0), "day 6 part 1"); Verifier.Verify(3323, Day06.Part2(0), "day 6 part 2"); Verifier.Verify(192, Day07.Part1(0), "day 7 part 1"); Verifier.Verify(12128, Day07.Part2(0), "day 7 part 2"); Verifier.Verify(1671, Day08.Part1(0), "day 8 part 1"); Verifier.Verify(892, Day08.Part2(0), "day 8 part 2"); Verifier.Verify(70639851, Day09.Part1(0), "day 9 part 1"); Verifier.Verify(8249240, Day09.Part2(0), "day 9 part 2"); Verifier.Verify(2450, Day10.Part1(0), "day 10 part 1"); Verifier.Verify(32396521357312, Day10.Part2(0), "day 10 part 2"); Verifier.Verify(2273, Day11.Part1(0), "day 11 part 1"); Verifier.Verify(2064, Day11.Part2(0), "day 11 part 2"); Verifier.Verify(1710, Day12.Part1(0), "day 12 part 1"); Verifier.Verify(62045, Day12.Part2(0), "day 12 part 2"); Verifier.Verify(119, Day13.Part1(), "day 13 part 1"); Verifier.Verify(1106724616194525, Day13.Part2(), "day 13 part 2"); Verifier.Verify(5875750429995, Day14.Part1(0), "day 14 part 1"); Verifier.Verify(5272149590143, Day14.Part2(0), "day 14 part 2"); Verifier.Verify(959, Day15.Part1(0), "day 15 part 1"); Verifier.Verify(116590, Day15.Part2(0), "day 15 part 2"); Verifier.Verify(25972, Day16.Part1(0), "day 16 part 1"); Verifier.Verify(622670335901, Day16.Part2(0), "day 16 part 2"); Verifier.Verify(353, Day17.Part1(0), "day 17 part 1"); Verifier.Verify(2472, Day17.Part2(0), "day 17 part 2"); Verifier.Verify(11076907812171, Day18.Part1(), "day 18 part 1"); Verifier.Verify(283729053022731, Day18.Part2(), "day 18 part 2"); Verifier.Verify(149, Day19.Part1(), "day 19 part 1"); Verifier.Verify(332, Day19.Part2(), "day 19 part 2"); Verifier.Verify(83775126454273, Day20.Part1(), "day 20 part 1"); Verifier.Verify(1993, Day20.Part2(), "day 20 part 2"); Verifier.Verify(2659, Day21.Part1(), "day 21 part 1"); Verifier.Verify("rcqb,cltx,nrl,qjvvcvz,tsqpn,xhnk,tfqsb,zqzmzl", Day21.Part2(), "day 21 part 2"); Verifier.Verify(31781, Day22.Part1(), "day 22 part 1"); Verifier.Verify(35154, Day22.Part2(), "day 22 part 2"); Verifier.Verify(75893264, Day23.Part1(), "day 23 part 1"); Verifier.Verify(38162588308, Day23.Part2(), "day 23 part 2"); Verifier.Verify(228, Day24.Part1(), "day 24 part 1"); Verifier.Verify(3672, Day24.Part2(), "day 24 part 2"); Verifier.Verify(181800, Day25.Part1(), "day 25 part 1"); Console.WriteLine("All tests for 2020 OK"); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { string UserSelection = ""; bool ContinueLoop = true; do { // Ask for userinput to select problem 1-25 // Select Test Input or Input Console.WriteLine("Please select a Day Number(1-25): "); UserSelection = Console.ReadLine(); string PartSelection = ""; string TestSelection = ""; switch (UserSelection) { case "1": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day1.Part1(ReadFile("Input/Problem1.txt"))); break; case "2": Console.WriteLine(Day1.Part1(ReadFile("TestInput/Problem1.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day1.Part2(ReadFile("Input/Problem1.txt"))); break; case "2": Console.WriteLine(Day1.Part2(ReadFile("TestInput/Problem1.txt"))); break; } break; } break; case "2": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day2.Part1(ReadFile("Input/Problem2.txt"))); break; case "2": Console.WriteLine(Day2.Part1(ReadFile("TestInput/Problem2.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day2.Part2(ReadFile("Input/Problem2.txt"))); break; case "2": Console.WriteLine(Day2.Part2(ReadFile("TestInput/Problem2.txt"))); break; } break; } break; case "3": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day3.Part1(ReadFile("Input/Problem3.txt"))); break; case "2": Console.WriteLine(Day3.Part1(ReadFile("TestInput/Problem3.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day3.Part2(ReadFile("Input/Problem3.txt"))); break; case "2": Console.WriteLine(Day3.Part2(ReadFile("TestInput/Problem3.txt"))); break; } break; } break; case "4": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day4.Part1(ReadFile("Input/Problem4.txt"))); break; case "2": Console.WriteLine(Day4.Part1(ReadFile("TestInput/Problem4.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day4.Part2(ReadFile("Input/Problem4.txt"))); break; case "2": Console.WriteLine(Day4.Part2(ReadFile("TestInput/Problem4.txt"))); break; } break; } break; case "5": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day5.Part1(ReadFile("Input/Problem5.txt"))); break; case "2": Console.WriteLine(Day5.Part1(ReadFile("TestInput/Problem5.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day5.Part2(ReadFile("Input/Problem5.txt"))); break; case "2": Console.WriteLine(Day5.Part2(ReadFile("TestInput/Problem5.txt"))); break; } break; } break; case "6": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day6.Part1(ReadFile("Input/Problem6.txt"))); break; case "2": Console.WriteLine(Day6.Part1(ReadFile("TestInput/Problem6.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day6.Part2(ReadFile("Input/Problem6.txt"))); break; case "2": Console.WriteLine(Day6.Part2(ReadFile("TestInput/Problem6.txt"))); break; } break; } break; case "7": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day7.Part1(ReadFile("Input/Problem7.txt"))); break; case "2": Console.WriteLine(Day7.Part1(ReadFile("TestInput/Problem7.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day7.Part2(ReadFile("Input/Problem7.txt"))); break; case "2": Console.WriteLine(Day7.Part2(ReadFile("TestInput/Problem7.txt"))); break; } break; } break; case "8": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day8.Part1(ReadFile("Input/Problem8.txt"))); break; case "2": Console.WriteLine(Day8.Part1(ReadFile("TestInput/Problem8.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day8.Part2(ReadFile("Input/Problem8.txt"))); break; case "2": Console.WriteLine(Day8.Part2(ReadFile("TestInput/Problem8.txt"))); break; } break; } break; case "9": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day9.Part1(ReadFile("Input/Problem9.txt"))); break; case "2": Console.WriteLine(Day9.Part1(ReadFile("TestInput/Problem9.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day9.Part2(ReadFile("Input/Problem9.txt"))); break; case "2": Console.WriteLine(Day9.Part2(ReadFile("TestInput/Problem9.txt"))); break; } break; } break; case "10": Console.WriteLine("Please Select Part Number 1 or 2: "); PartSelection = Console.ReadLine(); switch (PartSelection) { case "1": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day10.Part1(ReadFile("Input/Problem10.txt"))); break; case "2": Console.WriteLine(Day10.Part1(ReadFile("TestInput/Problem10.txt"))); break; } break; case "2": Console.WriteLine("Please Select Input or Test Input 1 or 2: "); TestSelection = Console.ReadLine(); switch (TestSelection) { case "1": Console.WriteLine(Day10.Part2(ReadFile("Input/Problem10.txt"))); break; case "2": Console.WriteLine(Day10.Part2(ReadFile("TestInput/Problem10.txt"))); break; } break; } break; case "X": case "x": ContinueLoop = false; break; default: Console.WriteLine("Sorry please select a number between 1-25"); break; } }while(ContinueLoop == true); // Day 1 // Day 2 // Console.WriteLine(Day2.Part1(ReadFile("Input/Problem2.txt"))); // Console.WriteLine(Day2.Part2(ReadFile("Input/Problem2.txt"))); // Console.WriteLine(Day2.Part1(ReadFile("TestInput/Problem2.txt"))); // Console.WriteLine(Day2.Part2(ReadFile("TestInput/Problem2.txt"))); // Day 3 // Console.WriteLine(Day3.Part1(ReadFile("Input/Problem3.txt"))); // Console.WriteLine(Day3.Part2(ReadFile("Input/Problem3.txt"))); // Console.WriteLine(Day3.Part1(ReadFile("TestInput/Problem3.txt"))); // Console.WriteLine(Day3.Part2(ReadFile("TestInput/Problem3.txt"))); // Day 4 // Console.WriteLine(Day4.Part1(ReadFile("Input/Problem4.txt"))); // Console.WriteLine(Day4.Part2(ReadFile("Input/Problem4.txt"))); // Console.WriteLine(Day4.Part1(ReadFile("TestInput/Problem4.txt"))); // Console.WriteLine(Day4.Part2(ReadFile("TestInput/Problem4.txt"))); // Day 5 // Console.WriteLine(Day5.Part1(ReadFile("Input/Problem5.txt"))); // Console.WriteLine(Day5.Part2(ReadFile("Input/Problem5.txt"))); // Console.WriteLine(Day5.Part1(ReadFile("TestInput/Problem5.txt"))); // Console.WriteLine(Day5.Part2(ReadFile("TestInput/Problem5.txt"))); // Day 6 // Console.WriteLine(Day6.Part1(ReadFile("Input/Problem6.txt"))); // Console.WriteLine(Day6.Part2(ReadFile("Input/Problem6.txt"))); // Console.WriteLine(Day6.Part1(ReadFile("TestInput/Problem6.txt"))); // Console.WriteLine(Day6.Part2(ReadFile("TestInput/Problem6.txt"))); // Day 7 // Console.WriteLine(Day7.Part1(ReadFile("Input/Problem7.txt"))); // Console.WriteLine(Day7.Part2(ReadFile("Input/Problem7.txt"))); // Console.WriteLine(Day7.Part1(ReadFile("TestInput/Problem7.txt"))); // Console.WriteLine(Day7.Part2(ReadFile("TestInput/Problem7.txt"))); // Day 8 // Console.WriteLine(Day8.Part1(ReadFile("Input/Problem8.txt"))); // Console.WriteLine(Day8.Part2(ReadFile("Input/Problem8.txt"))); // Console.WriteLine(Day8.Part1(ReadFile("TestInput/Problem8.txt"))); // Console.WriteLine(Day8.Part2(ReadFile("TestInput/Problem8.txt"))); // Day 9 // Console.WriteLine(Day9.Part1(ReadFile("Input/Problem9.txt"))); // Console.WriteLine(Day9.Part2(ReadFile("Input/Problem9.txt"))); // Console.WriteLine(Day9.Part1(ReadFile("TestInput/Problem9.txt"))); // Console.WriteLine(Day9.Part2(ReadFile("TestInput/Problem9.txt"))); // Day 10 // Console.WriteLine(Day10.Part1(ReadFile("Input/Problem10.txt"))); // Console.WriteLine(Day10.Part2(ReadFile("Input/Problem10.txt"))); // Console.WriteLine(Day10.Part1(ReadFile("TestInput/Problem10.txt"))); // Console.WriteLine(Day10.Part2(ReadFile("TestInput/Problem10.txt"))); }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Hello World!"); } else { switch (args[0]) { case "p1": Day1.FirstPuzzle(args.Skip(1).Select(int.Parse).ToArray()); break; case "p2": Day1.SecondPuzzle(args.Skip(1).Select(int.Parse).ToArray()); break; case "p3": Day2.ThirdPuzzle(args[1]); break; case "p4": Day2.FourthPuzzle(args[1]); break; case "p5": Day3.FifthPuzzle(args[1], args[2]); break; case "p6": Day3.SixthPuzzle(args[1], args[2]); break; case "p7": Day4.SeventhPuzzle(args[1]); break; case "p8": Day4.EigthPuzzle(args[1]); break; case "p9": Day5.NinthPuzzle(args[1]); break; case "p10": Day5.TenthPuzzle(args[1]); break; case "p11": Day6.EleventhPuzzle(args.Skip(1).ToArray()); break; case "p12": Day6.TwelthPuzzle(args.Skip(1).ToArray()); break; case "p13": Day7.ThirteenthPuzzle(args[1]); break; case "p14": Day7.FourteenthPuzzle(args[1]); break; case "p15": Day8.FifteenthPuzzle(args[1]); break; case "p16": Day8.SixteenthPuzzle(args[1]); break; case "p17": case "p18": Day9.SeventeenthPuzzle(args[1]); break; case "p19": Day10.NineteenthPuzzle(args.Skip(1).ToArray()); break; case "p20": Day10.TwentiethPuzzle(args.Skip(1).ToArray()); break; case "p21": Day11.TwentyfirstPuzzle(args[1]); break; case "p22": Day11.TwentysecondPuzzle(args[1]); break; case "p23": Day12.TwentythirdPuzzle(); break; case "p24": Day12.TwentyfourthPuzzle(); break; case "p25": Day13.TwentyfifthPuzzle(args[1]); break; case "p26": Day13.TwentysixthPuzzle(args[1]); break; case "p27": Day14.TwentyseventhPuzzle(); break; case "p28": Day14.TwentyeighthPuzzle(); break; default: Console.WriteLine("Hello World!"); break; } } }
static void Main(string[] args) { Console.WriteLine(); Console.WriteLine("Welcome to Advent of Code 2017! Please pass in which Day you would like to evaluate as a command line argument!"); Console.WriteLine(); int dayChallenge = Int32.Parse(args[0]); if (dayChallenge < 1 || dayChallenge > 25) { Console.WriteLine("Please pass in a valid day challenge between 1 and 25 :("); Console.WriteLine(); return; } switch (dayChallenge) { case 1: Day1.TestDay1("181445682966897848665963472661939865313976877194312684993521259486517527961396717561854825453963181134379574918373213732184697746668399631642622373684425326112585283946462323363991753895647177797691214784149215198715986947573668987188746878678399624533792551651335979847131975965677957755571358934665327487287312467771187981424785514785421781781976477326712674311994735947987383516699897916595433228294198759715959469578766739518475118771755787196238772345762941477359483456641194685333528329581113788599843621326313592354167846466415943566183192946217689936174884493199368681514958669615226362538622898367728662941275658917124167353496334664239539753835439929664552886538885727235662548783529353611441231681613535447417941911479391558481443933134283852879511395429489152435996669232681215627723723565872291296878528334773391626672491878762288953597499218397146685679387438634857358552943964839321464529237533868734473777756775687759355878519113426969197211824325893376812556798483325994128743242544899625215765851923959798197562831313891371735973761384464685316273343541852758525318144681364492173465174512856618292785483181956548813344752352933634979165667651165776587656468598791994573513652324764687515345959621493346623821965554755615219855842969932269414839446887613738174567989512857785566352285988991946436148652839391593178736624957214917527759574235133666461988355855613377789115472297915429318142824465141688559333787512328799783539285826471818279818457674417354335454395644435889386297695625378256613558911695145397779576526397241795181294322797687168326696497256684943829666672341162656479563522892141714998477865114944671225898297338685958644728534192317628618817551492975251364233974374724968483637518876583946828819994321129556511537619253381981544394112184655586964655164192552352534626295996968762388827294873362719636616182786976922445125551927969267591395292198155775434997827738862786341543524544822321112131815475829945625787561369956264826651461575948462782869972654343749617939132353399334744265286151177931594514857563664329299713436914721119746932159456287267887878779218815883191236858656959258484139254446341"); break; case 2: Day2.TestDay2(); break; case 3: Day3.TestDay3(265149); break; case 4: Day4.TestDay4(); break; case 5: Day5.TestDay5(); break; case 6: Day6.TestDay6(); break; case 7: Day7.TestDay7(); break; case 8: Day8.TestDay8(); break; case 9: Day9.TestDay9(); break; case 10: Day10.TestDay10(); break; case 11: Day11.TestDay11(); break; case 12: Day12.TestDay12(); break; case 13: Day13.TestDay13(); break; case 14: Day14.TestDay14(); break; case 15: Day15.TestDay15(); break; case 16: Day16.TestDay16(); break; case 17: Day17.TestDay17(); break; case 18: Day18.TestDay18(); break; case 19: Day19.TestDay19(); break; case 20: Day20.TestDay20(); break; case 21: Day21.TestDay21(); break; case 22: Day22.TestDay22(); break; case 23: Day23.TestDay23(); break; case 24: Day24.TestDay24(); break; case 25: Day25.TestDay25(); break; default: break; } return; }
static void Main(string[] args) { Console.WriteLine(Day10.Compute()); }
public static void TestAll() { try { Console.WriteLine("Running tests for 2021"); Verifier.Verify(1529, Day01.Part1(), "day 1 part 1"); Verifier.Verify(1567, Day01.Part2(), "day 1 part 2"); Verifier.Verify(1813801, Day02.Part1(), "day 2 part 1"); Verifier.Verify(1960569556, Day02.Part2(), "day 2 part 1"); Verifier.Verify(2724524, Day03.Part1(), "day 3 part 1"); Verifier.Verify(2775870, Day03.Part2(), "day 3 part 2"); Verifier.Verify(44736, Day04.Part1(), "day 4 part 1"); Verifier.Verify(1827, Day04.Part2(), "day 4 part 2"); Verifier.Verify(4728, Day05.Part1(), "day 5 part 1"); Verifier.Verify(17717, Day05.Part2(), "day 5 part 2"); Verifier.Verify(375482, Day06.Part1(), "day 6 part 1"); Verifier.Verify(1689540415957, Day06.Part2(), "day 6 part 2"); Verifier.Verify(356922, Day07.Part1(), "day 7 part 1"); Verifier.Verify(100347031, Day07.Part2(), "day 7 part 2"); Verifier.Verify(488, Day08.Part1(), "day 8 part 1"); Verifier.Verify(1040429, Day08.Part2(), "day 8 part 2"); Verifier.Verify(496, Day09.Part1(), "day 9 part 1"); Verifier.Verify(902880, Day09.Part2(), "day 9 part 2"); Verifier.Verify(294195, Day10.Part1(), "day 10 part 1"); Verifier.Verify(3490802734, Day10.Part2(), "day 10 part 2"); Verifier.Verify(1725, Day11.Part1(), "day 11 part 1"); Verifier.Verify(308, Day11.Part2(), "day 11 part 2"); Verifier.Verify(4338, Day12.Part1(), "day 12 part 1"); Verifier.Verify(114189, Day12.Part2(), "day 12 part 2"); Verifier.Verify(0, Day13.Part1(), "day 13 part 1"); Verifier.Verify(0, Day13.Part2(), "day 13 part 2"); Verifier.Verify(0, Day14.Part1(), "day 14 part 1"); Verifier.Verify(0, Day14.Part2(), "day 14 part 2"); Verifier.Verify(0, Day15.Part1(), "day 15 part 1"); Verifier.Verify(0, Day15.Part2(), "day 15 part 2"); Verifier.Verify(0, Day16.Part1(), "day 16 part 1"); Verifier.Verify(0, Day16.Part2(), "day 16 part 2"); Verifier.Verify(0, Day17.Part1(), "day 17 part 1"); Verifier.Verify(0, Day17.Part2(), "day 17 part 2"); Verifier.Verify(0, Day18.Part1(), "day 18 part 1"); Verifier.Verify(0, Day18.Part2(), "day 18 part 2"); Verifier.Verify(0, Day19.Part1(), "day 19 part 1"); Verifier.Verify(0, Day19.Part2(), "day 19 part 2"); Verifier.Verify(0, Day20.Part1(), "day 20 part 1"); Verifier.Verify(0, Day20.Part2(), "day 20 part 2"); Verifier.Verify(0, Day21.Part1(), "day 21 part 1"); Verifier.Verify(0, Day21.Part2(), "day 21 part 2"); Verifier.Verify(0, Day22.Part1(), "day 22 part 1"); Verifier.Verify(0, Day22.Part2(), "day 22 part 2"); Verifier.Verify(0, Day23.Part1(), "day 23 part 1"); Verifier.Verify(0, Day23.Part2(), "day 23 part 2"); Verifier.Verify(0, Day24.Part1(), "day 24 part 1"); Verifier.Verify(0, Day24.Part2(), "day 24 part 2"); Verifier.Verify(0, Day25.Part1(), "day 25 part 1"); Console.WriteLine("All tests for 2021 OK"); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { Day10 day10 = new Day10(); day10.Run(); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Need to specify day number (1-25)"); } else { Console.WriteLine($"Day {args[0]}"); if (args[0] == "1") { Console.WriteLine("Problem 1"); Console.WriteLine(Day1.Problem1("1122")); Console.WriteLine(Day1.Problem1("1111")); Console.WriteLine(Day1.Problem1("1234")); Console.WriteLine(Day1.Problem1("57276274387944537823652626177853384411146325384494935924454336611953119173638191671326254832624841593421667683474349154668177743437745965461678636631863541462893547616877914914662358836365421198516263335926544716331814125295712581158399321372683742773423626286669759415959391374744214595682795818615532673877868424196926497731144319736445141728123322962547288572434564178492753681842244888368542423832228211172842456231275738182764232265933625119312598161192193214898949267765417468348935134618964683127194391796165368145548814473129857697989322621368744725685183346825333247866734735894493395218781464346951777873929898961358796274889826894529599645442657423438562423853247543621565468819799931598754753467593832328147439341586125262733737128386961596394728159719292787597426898945198788211417854662948358422729471312456437778978749753927251431677533575752312447488337156956217451965643454445329758327129966657189332824969141448538681979632611199385896965946849725421978137753366252459914913637858783146735469758716752765718189175583956476935185985918536318424248425426398158278111751711911227818826766177996223718837428972784328925743869885232266127727865267881592395643836999244218345184474613129823933659422223685422732186536199153988717455568523781673393698356967355875123554797755491181791593156433735591529495984256519631187849654633243225118132152549712643273819314433877592644693826861523243946998615722951182474773173215527598949553185313259992227879964482121769617218685394776778423378182462422788277997523913176326468957342296368178321958626168785578977414537368686438348124283789748775163821457641135163495649331144436157836647912852483177542224864952271874645274572426458614384917923623627532487625396914111582754953944965462576624728896917137599778828769958626788685374749661741223741834844643725486925886933118382649581481351844943368484853956759877215252766294896496444835264357169642341291412768946589781812493421379575569593678354241223363739129813633236996588711791919421574583924743119867622229659211793468744163297478952475933163259769578345894367855534294493613767564497137369969315192443795512585")); Console.WriteLine(); Console.WriteLine("Problem 2"); Console.WriteLine(Day1.Problem2("1212")); Console.WriteLine(Day1.Problem2("1221")); Console.WriteLine(Day1.Problem2("123425")); Console.WriteLine(Day1.Problem2("123123")); Console.WriteLine(Day1.Problem2("12131415")); Console.WriteLine(Day1.Problem2("57276274387944537823652626177853384411146325384494935924454336611953119173638191671326254832624841593421667683474349154668177743437745965461678636631863541462893547616877914914662358836365421198516263335926544716331814125295712581158399321372683742773423626286669759415959391374744214595682795818615532673877868424196926497731144319736445141728123322962547288572434564178492753681842244888368542423832228211172842456231275738182764232265933625119312598161192193214898949267765417468348935134618964683127194391796165368145548814473129857697989322621368744725685183346825333247866734735894493395218781464346951777873929898961358796274889826894529599645442657423438562423853247543621565468819799931598754753467593832328147439341586125262733737128386961596394728159719292787597426898945198788211417854662948358422729471312456437778978749753927251431677533575752312447488337156956217451965643454445329758327129966657189332824969141448538681979632611199385896965946849725421978137753366252459914913637858783146735469758716752765718189175583956476935185985918536318424248425426398158278111751711911227818826766177996223718837428972784328925743869885232266127727865267881592395643836999244218345184474613129823933659422223685422732186536199153988717455568523781673393698356967355875123554797755491181791593156433735591529495984256519631187849654633243225118132152549712643273819314433877592644693826861523243946998615722951182474773173215527598949553185313259992227879964482121769617218685394776778423378182462422788277997523913176326468957342296368178321958626168785578977414537368686438348124283789748775163821457641135163495649331144436157836647912852483177542224864952271874645274572426458614384917923623627532487625396914111582754953944965462576624728896917137599778828769958626788685374749661741223741834844643725486925886933118382649581481351844943368484853956759877215252766294896496444835264357169642341291412768946589781812493421379575569593678354241223363739129813633236996588711791919421574583924743119867622229659211793468744163297478952475933163259769578345894367855534294493613767564497137369969315192443795512585")); } else if (args[0] == "2") { Console.WriteLine("Problem 1"); Console.WriteLine(Day2.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day2.Problem2()); } else if (args[0] == "3") { Console.WriteLine("Problem 1"); Console.WriteLine(Day3.Problem1(12)); Console.WriteLine(Day3.Problem1(23)); Console.WriteLine(Day3.Problem1(1024)); Console.WriteLine(Day3.Problem1(325489)); Console.WriteLine("Problem 2"); Console.WriteLine(Day3.Problem2(325489)); } else if (args[0] == "4") { Console.WriteLine("Problem 1"); Console.WriteLine(Day4.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day4.Problem2()); } else if (args[0] == "5") { Console.WriteLine("Problem 1"); Console.WriteLine(Day5.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day5.Problem2()); } else if (args[0] == "6") { Console.WriteLine("Problem 1"); Console.WriteLine(Day6.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day6.Problem2()); } else if (args[0] == "7") { Console.WriteLine("Problem 1"); Console.WriteLine(Day7.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day7.Problem2()); } else if (args[0] == "8") { Console.WriteLine("Problem 1"); Console.WriteLine(Day8.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day8.Problem2()); } else if (args[0] == "9") { Console.WriteLine("Problem 1"); Console.WriteLine(Day9.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day9.Problem2()); } else if (args[0] == "10") { Console.WriteLine("Problem 1"); Console.WriteLine(Day10.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day10.Problem2()); } else if (args[0] == "11") { Console.WriteLine("Problem 1"); Console.WriteLine(Day11.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day11.Problem2()); } else if (args[0] == "12") { Console.WriteLine("Problem 1"); Console.WriteLine(Day12.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day12.Problem2()); } else if (args[0] == "13") { Console.WriteLine("Problem 1"); Console.WriteLine(Day13.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day13.Problem2()); } else if (args[0] == "14") { Console.WriteLine("Problem 1"); Console.WriteLine(Day14.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day14.Problem2()); } else if (args[0] == "15") { Console.WriteLine("Problem 1"); Console.WriteLine(Day15.Problem1(516, 190)); Console.WriteLine("Problem 2"); Console.WriteLine(Day15.Problem2(516, 190)); } else if (args[0] == "16") { Console.WriteLine("Problem 1"); Console.WriteLine(Day16.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day16.Problem2()); } else if (args[0] == "17") { Console.WriteLine("Problem 1"); Console.WriteLine(Day17.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day17.Problem2()); } else if (args[0] == "18") { Console.WriteLine("Problem 1"); Console.WriteLine(Day18.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day18.Problem2()); } else if (args[0] == "19") { Console.WriteLine("Problem 1"); Console.WriteLine(Day19.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day19.Problem2()); } else if (args[0] == "20") { Console.WriteLine("Problem 1"); Console.WriteLine(Day20.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day20.Problem2()); } else if (args[0] == "21") { Console.WriteLine("Problem 1"); Console.WriteLine(Day21.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day21.Problem2()); } else if (args[0] == "22") { Console.WriteLine("Problem 1"); Console.WriteLine(Day22.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day22.Problem2()); } else if (args[0] == "23") { Console.WriteLine("Problem 1"); Console.WriteLine(Day23.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day23.Problem2()); } else if (args[0] == "24") { Console.WriteLine("Problem 1"); Console.WriteLine(Day24.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day24.Problem2()); } else if (args[0] == "25") { Console.WriteLine("Problem 1"); Console.WriteLine(Day25.Problem1()); Console.WriteLine("Problem 2"); Console.WriteLine(Day25.Problem2()); } } }