public static void PartOne() { Console.WriteLine("Day Ten - Part One"); List <int> adapters = PuzzleInputHelper.GetInputLines("DayTen.txt") .Select(Int32.Parse).OrderBy(i => i).ToList(); Console.WriteLine($"There are {adapters.Count} adapters"); Console.WriteLine("Adapters in order:"); Console.WriteLine(String.Join(", ", adapters)); int oneDiff = 1; int threeDiff = 1; for (int i = 0; i < adapters.Count; i++) { if (i > 0) { if (adapters[i] - adapters[i - 1] == 1) { oneDiff++; } else if (adapters[i] - adapters[i - 1] == 3) { threeDiff++; } } } Console.WriteLine("Product of 1-differences and 3-differences: " + oneDiff * threeDiff); Console.WriteLine("Day Ten - End of Part One"); }
public static void PartOne() { Console.WriteLine("Day seven - Part One"); List <BagRule> rules = PuzzleInputHelper.GetInputLines("DaySeven_Solene.txt") .Select(BagRule.FromLine) .ToList(); Console.WriteLine($"There are {rules.Count} rules"); List <string> countedBags = new List <string>(); Queue <string> bagsToCheck = new Queue <string>(); bagsToCheck.Enqueue("shiny gold"); while (bagsToCheck.Count > 0) { string currentBagToCheck = bagsToCheck.Dequeue(); countedBags.Add(currentBagToCheck); var bagsAroundCurrent = rules.Where(br => br.CanContain(currentBagToCheck)).ToList(); bagsAroundCurrent.ForEach(bag => { if (!countedBags.Contains(bag.Color) && !bagsToCheck.Contains(bag.Color)) { bagsToCheck.Enqueue(bag.Color); } }); } Console.WriteLine($"There were {countedBags.Count} counted bags"); Console.WriteLine("Day seven - End of part One"); }
public static void PartTwo() { Console.WriteLine("Day four - Part Two"); List <List <string> > lines = PuzzleInputHelper.GetInputLinesBatched("DayFour.txt", String.Empty); List <Passport> passports = lines.Select(Passport.FromLines).ToList(); Console.WriteLine($"There are only {passports.Count(p => p.IsDataValid())} data-valid passports"); Console.WriteLine("Day four - End of part Two"); }
public static void PartTwo() { Console.WriteLine("Day Two - Part Two"); List <PasswordWithPolicy> passwords = PuzzleInputHelper.GetInputLines("DayTwo.txt") .Select(PasswordWithPolicy.FromLine).ToList(); int validPasswords = passwords.Count(p => p.SatisfiesNewPolicy()); Console.WriteLine($"There are {validPasswords} valid passwords under new policy"); Console.WriteLine("Day Two - End of part Two"); }
public static void PartOne() { Console.WriteLine("Day eight - Part One"); OpcodeInstruction[] opcodes = PuzzleInputHelper.GetInputLines("DayEight.txt") .Select(OpcodeInstruction.FromLine).ToArray(); OpcodeMachine opm = new OpcodeMachine(opcodes); opm.Run(); Console.WriteLine("Day eight - End of part One"); }
public static void PartOne() { Console.WriteLine("Day one - Part One"); List <int> lines = PuzzleInputHelper.GetInputLines("DayOne.txt").Select(l => int.Parse(l)).ToList(); Console.WriteLine($"Input has {lines.Count} lines"); int prod = lines.SelectMany(a => lines.Select(b => (a + b, a * b))) .Where(sum => sum.Item1 == 2020).First().Item2; Console.WriteLine($"Product of lines with sum 2020 is {prod}"); Console.WriteLine("Day one - End of part One"); }
public static void PartTwo() { Console.WriteLine("Day seven - Part Two"); List <BagRule> rules = PuzzleInputHelper.GetInputLines("DaySeven.txt") .Select(BagRule.FromLine) .ToList(); int sumOfBags = rules.First(br => br.Color == "shiny gold").BagsInside(rules).Sum(); Console.WriteLine($"A shiny gold bag will contain {sumOfBags} bags in it"); Console.WriteLine("Day seven - End of Part Two"); }
public static void PartOne() { Console.WriteLine("Day Three - Part One"); char[][] trees = PuzzleInputHelper.GetInputMatrix("DayThree.txt"); int ouchies = Weeeeeeeeeeeee(trees, 3, 1); string displayRectangle = MatrixHelper <char> .GetDisplayRectangle(trees, new Rectangle(0, 0, 20, 20), MatrixWrap.WrapHorizontally | MatrixWrap.WrapVertically); Console.WriteLine(displayRectangle); Console.WriteLine($"You have {ouchies} ouchies. Oof!"); Console.WriteLine("Day Three - End of Part One"); }
public static void PartTwo() { Console.WriteLine("Day six - Part Two"); List <List <string> > lines = PuzzleInputHelper.GetInputLinesBatched("DaySix.txt", String.Empty); List <string> uniqueAnswers = new List <string>(); lines.Aggregate(uniqueAnswers, (ua, answers) => { ua.Add(String.Join("", String.Join("", answers).Distinct())); return(ua); }); int sum = lines.Zip(uniqueAnswers, (answers, ua) => ua.Count(c => String.Join("", answers).Count(a => a == c) == answers.Count)).Sum(); Console.WriteLine($"Sum of all groups count is {sum}"); Console.WriteLine("Day six - End of Part Two"); }
public static void PartTwo() { Console.WriteLine("Day Three - Part Two"); char[][] trees = PuzzleInputHelper.GetInputMatrix("DayThree.txt"); long ouchies = Weeeeeeeeeeeee(trees, 1, 1); ouchies *= AnswerToPartOne; ouchies *= Weeeeeeeeeeeee(trees, 5, 1); ouchies *= Weeeeeeeeeeeee(trees, 7, 1); ouchies *= Weeeeeeeeeeeee(trees, 1, 2); Console.WriteLine($"You have {ouchies} ouchies in your kamikaze run. Oof!"); Console.WriteLine("Day Three - End of Part Two"); }
public static void PartOne() { char[][] seats = PuzzleInputHelper.GetInputMatrix("DayEleven.txt"); string displayRect = MatrixHelper <char> .GetDisplayRectangle(seats, new System.Drawing.Rectangle(0, 0, 20, 20)); Console.WriteLine(displayRect); OneRound(seats); Console.WriteLine(); displayRect = MatrixHelper <char> .GetDisplayRectangle(seats, new System.Drawing.Rectangle(0, 0, 20, 20)); Console.WriteLine(displayRect); }
public static void PartOne() { Console.WriteLine("Day six - Part One"); List <List <string> > lines = PuzzleInputHelper.GetInputLinesBatched("DaySix.txt", String.Empty); List <string> uniqueAnswers = new List <string>(); lines.Aggregate(uniqueAnswers, (ua, answers) => { ua.Add(String.Join("", String.Join("", answers).Distinct())); return(ua); }); int sumOfUniqueAnswers = uniqueAnswers.Sum(ua => ua.Length); Console.WriteLine($"Unique answers for first group is {uniqueAnswers[0]}"); Console.WriteLine($"Sum of all groups count is {sumOfUniqueAnswers}"); Console.WriteLine("Day six - End of part One"); }
public static void PartOne() { Console.WriteLine("Day Nine - Part One"); List <BigInteger> inputs = PuzzleInputHelper.GetInputLines("DayNine.txt") .Select(BigInteger.Parse).ToList(); var valids = inputs.Select((value, index) => { if (index < 25) { return(value, true); } return(value, GetValidSumsFor(inputs.Skip(index - 25).Take(25)).Contains(value)); }); Console.WriteLine($"The first number to not respect a valid sum is {valids.First(i => !i.Item2).Item1}"); Console.WriteLine("Day Nine - End of Part One"); }
//2037 too high public static void PartTwo() { Console.WriteLine("Day eight - Part Two"); OpcodeInstruction[] opcodes = PuzzleInputHelper.GetInputLines("DayEight.txt") .Select(OpcodeInstruction.FromLine).ToArray(); OpcodeMachine opm = new OpcodeMachine(opcodes); try { opm.BreakLoop(); Console.WriteLine("Program terminated with accumulator = " + opm.Accumulator); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Day eight - End of Part Two"); }
public static void PartTwo() { Console.WriteLine("Day Nine - Part Two"); List <BigInteger> inputs = PuzzleInputHelper.GetInputLines("DayNine.txt") .Select(BigInteger.Parse).ToList(); BigInteger answerToPartOne = 373803594; BigInteger runningSum = inputs[0]; int minIndex = 0; int maxIndex = 0; while (runningSum != answerToPartOne) { if (runningSum > answerToPartOne || runningSum < 0) { runningSum -= inputs[minIndex]; minIndex++; } else if (runningSum < answerToPartOne) { maxIndex++; runningSum += inputs[maxIndex]; } } Console.WriteLine($"Sum of numbers between {minIndex} and {maxIndex} indexes are {answerToPartOne}"); BigInteger sum = 0; BigInteger min = 0; BigInteger max = 0; for (int i = minIndex; i < maxIndex + 1; i++) { if (min == 0 || inputs[i] < min) { min = inputs[i]; } if (max < inputs[i]) { max = inputs[i]; } sum += inputs[i]; } Console.WriteLine($"Sum is {sum}"); Console.WriteLine($"min + max = {min + max}"); Console.WriteLine("Day Nine - End of Part Two"); }