Code cleanup

This commit is contained in:
2023-12-02 18:27:00 +01:00
parent 4d8bfbb377
commit 4b3d0fd0b6
78 changed files with 6814 additions and 6950 deletions

View File

@@ -1,80 +1,78 @@
namespace AdventOfCode2017
namespace AdventOfCode2017;
/*
*
--- Day 1: Inverse Captcha ---
The night before Christmas, one of Santa's Elves calls you in a panic. "The printer's broken! We can't print the Naughty or Nice List!" By the time you make it to sub-basement 17, there are only a few minutes until midnight. "We have a big problem," she says; "there must be almost fifty bugs in this system, but nothing else can print The List. Stand in this square, quick! There's no time to explain; if you can convince them to pay you in stars, you'll be able to--" She pulls a lever and the world goes blurry.
When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day millisecond in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
You're standing in a room with "digitization quarantine" written in LEDs along one wall. The only door is locked, but it includes a small interface. "Restricted Area - Strictly No Digitized Users Allowed."
It goes on to explain that you may only leave by solving a captcha to prove you're not a human. Apparently, you only get one millisecond to solve the captcha: too fast for a normal human, but it feels like hours to you.
The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list.
For example:
1122 produces a sum of 3 (1 + 2) because the first digit (1) matches the second digit and the third digit (2) matches the fourth digit.
1111 produces 4 because each digit (all 1) matches the next.
1234 produces 0 because no digit matches the next.
91212129 produces 9 because the only digit that matches the next one is the last digit, 9.
What is the solution to your captcha?
--- Part Two ---
You notice a progress bar that jumps to 50% completion. Apparently, the door isn't yet satisfied, but it did emit a star as encouragement. The instructions change:
Now, instead of considering the next digit, it wants you to consider the digit halfway around the circular list. That is, if your list contains 10 items, only include a digit in your sum if the digit 10/2 = 5 steps forward matches it. Fortunately, your list has an even number of elements.
For example:
1212 produces 6: the list contains 4 items, and all four digits match the digit 2 items ahead.
1221 produces 0, because every comparison is between a 1 and a 2.
123425 produces 4, because both 2s match each other, but no other digit has a match.
123123 produces 12.
12131415 produces 4.
What is the solution to your new captcha?
*/
public class Day01 : IDay
{
/*
*
--- Day 1: Inverse Captcha ---
The night before Christmas, one of Santa's Elves calls you in a panic. "The printer's broken! We can't print the Naughty or Nice List!" By the time you make it to sub-basement 17, there are only a few minutes until midnight. "We have a big problem," she says; "there must be almost fifty bugs in this system, but nothing else can print The List. Stand in this square, quick! There's no time to explain; if you can convince them to pay you in stars, you'll be able to--" She pulls a lever and the world goes blurry.
When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day millisecond in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
You're standing in a room with "digitization quarantine" written in LEDs along one wall. The only door is locked, but it includes a small interface. "Restricted Area - Strictly No Digitized Users Allowed."
It goes on to explain that you may only leave by solving a captcha to prove you're not a human. Apparently, you only get one millisecond to solve the captcha: too fast for a normal human, but it feels like hours to you.
The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list.
For example:
1122 produces a sum of 3 (1 + 2) because the first digit (1) matches the second digit and the third digit (2) matches the fourth digit.
1111 produces 4 because each digit (all 1) matches the next.
1234 produces 0 because no digit matches the next.
91212129 produces 9 because the only digit that matches the next one is the last digit, 9.
What is the solution to your captcha?
--- Part Two ---
You notice a progress bar that jumps to 50% completion. Apparently, the door isn't yet satisfied, but it did emit a star as encouragement. The instructions change:
Now, instead of considering the next digit, it wants you to consider the digit halfway around the circular list. That is, if your list contains 10 items, only include a digit in your sum if the digit 10/2 = 5 steps forward matches it. Fortunately, your list has an even number of elements.
For example:
1212 produces 6: the list contains 4 items, and all four digits match the digit 2 items ahead.
1221 produces 0, because every comparison is between a 1 and a 2.
123425 produces 4, because both 2s match each other, but no other digit has a match.
123123 produces 12.
12131415 produces 4.
What is the solution to your new captcha?
*/
public class Day01 : IDay
public string ResolvePart1(string[] inputs)
{
public string ResolvePart1(string[] inputs)
string input = inputs[0];
int value = 0;
for(int i = 0; i < input.Length; i++)
{
string input = inputs[0];
int value = 0;
for(int i = 0; i < input.Length; i++)
int nextI = (i + 1) % input.Length;
if(input[i] == input[nextI])
{
int nextI = (i + 1) % input.Length;
if(input[i] == input[nextI])
{
value += (input[i] - '0');
}
value += (input[i] - '0');
}
return value.ToString();
}
public string ResolvePart2(string[] inputs)
{
string input = inputs[0];
int value = 0;
int inputLength = input.Length;
int inputHalfLength = inputLength / 2;
for (int i = 0; i < inputLength; i++)
{
int nextI = (i + inputHalfLength) % inputLength;
if (input[i] == input[nextI])
{
value += (input[i] - '0');
}
}
return value.ToString();
}
return value.ToString();
}
}
public string ResolvePart2(string[] inputs)
{
string input = inputs[0];
int value = 0;
int inputLength = input.Length;
int inputHalfLength = inputLength / 2;
for (int i = 0; i < inputLength; i++)
{
int nextI = (i + inputHalfLength) % inputLength;
if (input[i] == input[nextI])
{
value += (input[i] - '0');
}
}
return value.ToString();
}
}

View File

@@ -1,99 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2017
namespace AdventOfCode2017;
/*
--- Day 2: Corruption Checksum ---
As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"
The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.
For example, given the following spreadsheet:
5 1 9 5
7 5 3
2 4 6 8
The first row's largest and smallest values are 9 and 1, and their difference is 8.
The second row's largest and smallest values are 7 and 3, and their difference is 4.
The third row's difference is 6.
In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
What is the checksum for the spreadsheet in your puzzle input?
--- Part Two ---
"Great work; looks like we're on the right track after all. Here's a star for your effort." However, the program seems a little worried. Can programs be worried?
"Based on what we're seeing, it looks like all the User wanted is some information about the evenly divisible values in the spreadsheet. Unfortunately, none of us are equipped for that kind of calculation - most of us specialize in bitwise operations."
It sounds like the goal is to find the only two numbers in each row where one evenly divides the other - that is, where the result of the division operation is a whole number. They would like you to find those numbers on each line, divide them, and add up each line's result.
For example, given the following spreadsheet:
5 9 2 8
9 4 7 3
3 8 6 5
In the first row, the only two numbers that evenly divide are 8 and 2; the result of this division is 4.
In the second row, the two numbers are 9 and 3; the result is 3.
In the third row, the result is 2.
In this example, the sum of the results would be 4 + 3 + 2 = 9.
What is the sum of each row's result in your puzzle input?
*/
public class Day02 : IDay
{
/*
--- Day 2: Corruption Checksum ---
As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"
The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.
For example, given the following spreadsheet:
5 1 9 5
7 5 3
2 4 6 8
The first row's largest and smallest values are 9 and 1, and their difference is 8.
The second row's largest and smallest values are 7 and 3, and their difference is 4.
The third row's difference is 6.
In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.
What is the checksum for the spreadsheet in your puzzle input?
--- Part Two ---
"Great work; looks like we're on the right track after all. Here's a star for your effort." However, the program seems a little worried. Can programs be worried?
"Based on what we're seeing, it looks like all the User wanted is some information about the evenly divisible values in the spreadsheet. Unfortunately, none of us are equipped for that kind of calculation - most of us specialize in bitwise operations."
It sounds like the goal is to find the only two numbers in each row where one evenly divides the other - that is, where the result of the division operation is a whole number. They would like you to find those numbers on each line, divide them, and add up each line's result.
For example, given the following spreadsheet:
5 9 2 8
9 4 7 3
3 8 6 5
In the first row, the only two numbers that evenly divide are 8 and 2; the result of this division is 4.
In the second row, the two numbers are 9 and 3; the result is 3.
In the third row, the result is 2.
In this example, the sum of the results would be 4 + 3 + 2 = 9.
What is the sum of each row's result in your puzzle input?
*/
public class Day02 : IDay
public string ResolvePart1(string[] inputs)
{
public string ResolvePart1(string[] inputs)
int checksum = 0;
foreach(string input in inputs)
{
int checksum = 0;
foreach(string input in inputs)
{
int[] row = input
.Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(cell => Convert.ToInt32(cell))
.ToArray();
int max = row.Max();
int min = row.Min();
checksum += (max - min);
}
return checksum.ToString();
int[] row = input
.Split(new[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(cell => Convert.ToInt32(cell))
.ToArray();
int max = row.Max();
int min = row.Min();
checksum += (max - min);
}
return checksum.ToString();
}
public string ResolvePart2(string[] inputs)
public string ResolvePart2(string[] inputs)
{
int checksum = 0;
foreach (string input in inputs)
{
int checksum = 0;
foreach (string input in inputs)
{
int[] row = input
.Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(cell => Convert.ToInt32(cell))
.ToArray();
int[] row = input
.Split(new[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries)
.Select(cell => Convert.ToInt32(cell))
.ToArray();
for (int i = 0; i < (row.Length - 1); i++)
for (int i = 0; i < (row.Length - 1); i++)
{
for (int j = i + 1; j < row.Length; j++)
{
for (int j = i + 1; j < row.Length; j++)
int max = Math.Max(row[i], row[j]);
int min = Math.Min(row[i], row[j]);
if ((max % min) == 0)
{
int max = Math.Max(row[i], row[j]);
int min = Math.Min(row[i], row[j]);
if ((max % min) == 0)
{
checksum += (max / min);
}
checksum += (max / min);
}
}
}
return checksum.ToString();
}
return checksum.ToString();
}
}
}

View File

@@ -1,47 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2017;
namespace AdventOfCode2017
/*
*
--- Day 3: Spiral Memory ---
You come across an experimental new kind of memory stored on an infinite two-dimensional grid.
Each square on the grid is allocated in a spiral pattern starting at a location marked 1 and then counting up while spiraling outward. For example, the first few squares are allocated like this:
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23---> ...
While this is very space-efficient (no squares are skipped), requested data must be carried back to square 1 (the location of the only access port for this memory system) by programs that can only move up, down, left, or right. They always take the shortest path: the Manhattan Distance between the location of the data and square 1.
For example:
Data from square 1 is carried 0 steps, since it's at the access port.
Data from square 12 is carried 3 steps, such as: down, left, left.
Data from square 23 is carried only 2 steps: up twice.
Data from square 1024 must be carried 31 steps.
How many steps are required to carry the data from the square identified in your puzzle input all the way to the access port?
*/
public class Day03 : IDay
{
/*
*
--- Day 3: Spiral Memory ---
You come across an experimental new kind of memory stored on an infinite two-dimensional grid.
Each square on the grid is allocated in a spiral pattern starting at a location marked 1 and then counting up while spiraling outward. For example, the first few squares are allocated like this:
17 16 15 14 13
18 5 4 3 12
19 6 1 2 11
20 7 8 9 10
21 22 23---> ...
While this is very space-efficient (no squares are skipped), requested data must be carried back to square 1 (the location of the only access port for this memory system) by programs that can only move up, down, left, or right. They always take the shortest path: the Manhattan Distance between the location of the data and square 1.
For example:
Data from square 1 is carried 0 steps, since it's at the access port.
Data from square 12 is carried 3 steps, such as: down, left, left.
Data from square 23 is carried only 2 steps: up twice.
Data from square 1024 must be carried 31 steps.
How many steps are required to carry the data from the square identified in your puzzle input all the way to the access port?
*/
public class Day03 : IDay
public string ResolvePart1(string[] inputs)
{
public string ResolvePart1(string[] inputs)
{
return null;
}
public string ResolvePart2(string[] inputs)
{
return null;
}
return null;
}
}
public string ResolvePart2(string[] inputs)
{
return null;
}
}

View File

@@ -1,8 +1,7 @@
namespace AdventOfCode2017
namespace AdventOfCode2017;
public interface IDay
{
public interface IDay
{
string ResolvePart1(string[] inputs);
string ResolvePart2(string[] inputs);
}
}
string ResolvePart1(string[] inputs);
string ResolvePart2(string[] inputs);
}

View File

@@ -1,29 +1,28 @@
using System;
using System.IO;
namespace AdventOfCode2017
namespace AdventOfCode2017;
public class Program
{
public class Program
private static void Main()
{
private static void Main(string[] args)
int currentDayNumber = 3;
IDay currentDay = null;
switch (currentDayNumber)
{
int currentDayNumber = 3;
IDay currentDay = null;
switch (currentDayNumber)
{
case 1: currentDay = new Day01(); break;
case 2: currentDay = new Day02(); break;
case 3: currentDay = new Day03(); break;
}
string[] linesDay = File.ReadAllLines(string.Format("inputs/Day{0:00}.txt", currentDayNumber));
string resultPart1 = currentDay.ResolvePart1(linesDay);
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
string resultPart2 = currentDay.ResolvePart2(linesDay);
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, currentDayNumber);
Console.Read();
case 1: currentDay = new Day01(); break;
case 2: currentDay = new Day02(); break;
case 3: currentDay = new Day03(); break;
}
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
string resultPart1 = currentDay.ResolvePart1(linesDay);
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
string resultPart2 = currentDay.ResolvePart2(linesDay);
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, currentDayNumber);
Console.Read();
}
}
}