chore(*): Move old solutions into a separate folder

This commit is contained in:
Josh Creek
2023-11-30 12:51:45 +00:00
parent ed3eb9cb54
commit b78d79a3af
117 changed files with 141 additions and 141 deletions
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Day_01</RootNamespace>
</PropertyGroup>
</Project>
+69
View File
@@ -0,0 +1,69 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace Day_01
{
class Program
{
static void Main(string[] args)
{
//Part1();
Part2();
}
static void Part1()
{
var frequency = 0;
var lines = File.ReadAllLines("input.txt");
foreach (var line in lines)
{
if (line.Substring(0,1) == "+")
{
frequency += Int32.Parse(line.Substring(1));
}
else
{
frequency -= Int32.Parse(line.Substring(1));
}
}
Console.WriteLine("Part 1: The resulting frequency is " + frequency);
}
static void Part2()
{
int frequency = 0;
List<int> frequencyHistory = new List<int>();
int loopCount = 0;
bool foundDuplicate = false;
var lines = File.ReadAllLines("input.txt");
while (!foundDuplicate) {
foreach (var line in lines)
{
if (line.Substring(0,1) == "+")
{
frequency += Int32.Parse(line.Substring(1));
}
else
{
frequency -= Int32.Parse(line.Substring(1));
}
if (frequencyHistory.Contains(frequency)) {
Console.WriteLine("The first repeated frequency is " + frequency);
foundDuplicate = true;
break;
}
else {
frequencyHistory.Add(frequency);
}
}
loopCount += 1;
}
Console.WriteLine("The loop count is " + loopCount);
}
}
}
+16
View File
@@ -0,0 +1,16 @@
After feeling like you've been falling for a few minutes, you look at the device's tiny screen. "Error: Device must be calibrated before first use. Frequency drift detected. Cannot maintain destination lock." Below the message, the device shows a sequence of changes in frequency (your puzzle input). A value like +6 means the current frequency increases by 6; a value like -3 means the current frequency decreases by 3.
For example, if the device displays frequency changes of +1, -2, +3, +1, then starting from a frequency of zero, the following changes would occur:
Current frequency 0, change of +1; resulting frequency 1.
Current frequency 1, change of -2; resulting frequency -1.
Current frequency -1, change of +3; resulting frequency 2.
Current frequency 2, change of +1; resulting frequency 3.
In this example, the resulting frequency is 3.
Here are other example situations:
+1, +1, +1 results in 3
+1, +1, -2 results in 0
-1, -2, -3 results in -6
Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied?
+20
View File
@@ -0,0 +1,20 @@
You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice.
For example, using the same list of changes above, the device would loop as follows:
Current frequency 0, change of +1; resulting frequency 1.
Current frequency 1, change of -2; resulting frequency -1.
Current frequency -1, change of +3; resulting frequency 2.
Current frequency 2, change of +1; resulting frequency 3.
(At this point, the device continues from the start of the list.)
Current frequency 3, change of +1; resulting frequency 4.
Current frequency 4, change of -2; resulting frequency 2, which has already been seen.
In this example, the first frequency reached twice is 2. Note that your device might need to repeat its list of frequency changes many times before a duplicate frequency is found, and that duplicates might be found while in the middle of processing the list.
Here are other examples:
+1, -1 first reaches 0 twice.
+3, +3, +4, -2, -4 first reaches 10 twice.
-6, +3, +8, +5, -6 first reaches 5 twice.
+7, +7, -2, -7, -4 first reaches 14 twice.
What is the first frequency your device reaches twice?
+977
View File
@@ -0,0 +1,977 @@
-12
-6
-12
+1
+3
+3
-1
+10
-8
-9
-11
-2
-7
+15
+16
+14
-2
-5
+11
-8
-5
-1
-19
-14
+6
-16
-8
-13
-19
-11
+3
-19
+3
-19
+9
-15
-11
+18
-9
+13
-17
-16
-13
-16
+19
+17
-18
-8
-5
+6
+9
+8
-7
-8
+2
-9
+2
-9
-5
-3
+4
-13
-5
+11
+14
+5
+17
-1
+9
+6
+14
-9
+4
-3
-13
-5
+13
-2
-10
-18
-12
+4
+13
-10
-11
-10
-17
-13
+12
-19
-7
-13
+5
-8
-11
+5
+7
+17
-14
+22
+14
+7
-8
+7
-19
+14
-20
+16
+12
+3
+5
+1
-8
+1
+15
+3
-6
-8
+9
+3
-19
-19
-19
+1
-16
-13
+5
-13
+2
-15
-15
-4
+12
+1
-10
-5
-11
-9
-11
-7
+10
-18
+16
-12
-19
-17
-18
+2
+15
+11
+9
-17
+4
+9
-18
-6
-1
-1
-18
-15
-18
-7
+16
+18
+18
-2
-4
+1
+15
+16
+18
+7
-18
+6
+8
+15
-8
-16
-3
+11
+9
+1
+4
-18
+3
-16
-14
-18
-10
+6
-12
-12
-2
-8
+1
-3
-11
+1
-5
-4
-5
+8
+8
-4
-10
+16
-1
+3
+9
+6
+24
+12
-2
+11
-1
-9
+21
-15
+12
+19
-3
+21
+20
+16
-4
+15
+9
+13
-16
+13
-1
-16
+13
+19
+14
+19
+14
-17
+18
+1
+11
+18
+18
+22
-8
+18
-1
+19
-11
-20
+11
+8
-11
+25
+13
+3
-1
-3
+17
+15
+7
+19
-7
+19
-1
-12
-14
+17
-15
-1
-18
+9
+14
-19
+10
-9
-11
+7
+20
+20
-1
+19
+1
+7
-19
-15
+3
+1
+17
+11
-7
+15
-7
-10
+13
-24
-21
-4
-4
-14
+6
+3
-25
+9
-7
+15
+12
+14
+20
-11
-11
-15
-14
-9
-2
-2
-3
-1
-18
-2
+6
+17
+9
-1
+18
+20
+21
+27
-17
-11
-4
-18
+24
+33
+4
+12
+8
+8
-1
-17
+6
-18
+16
+4
+1
+6
-1
-11
+18
+15
+17
-4
+13
+1
-20
+18
+3
-16
-4
-12
-10
+8
-18
+22
+21
+12
+1
+6
-24
+7
+1
+11
+14
+20
-5
-2
+4
+9
-20
+60
+15
+18
+14
-19
+13
+3
+7
+8
+5
-14
-13
+20
+5
-1
-15
+29
+14
-19
+7
-10
+13
+3
-7
-2
-19
+8
-15
-13
-13
-1
-9
-14
+10
-9
+18
-3
-12
-7
+21
+2
+7
+7
+10
-15
-16
-6
-8
-18
+11
+13
+7
+10
-14
-14
+17
+22
+23
+15
-4
+32
+7
-5
-3
-10
-14
+9
+12
+10
-12
+17
+1
-19
+16
+14
-2
+1
-7
+17
+16
-8
-15
+18
+19
+14
+52
+8
-22
-2
-2
+13
+6
-4
+2
+20
-14
-73
+119
+20
+26
+4
+9
+14
-42
-18
+44
+18
-23
+77
-11
+15
+52
+29
-7
-11
+31
-29
+5
-20
+435
+15
-156
+71279
-19
-2
+11
-4
-1
-15
+8
+14
+19
-16
-13
+19
+3
-7
-1
-12
-15
-14
-2
+14
+8
-1
-1
-7
-2
-4
-8
-8
+7
+10
-14
-2
-13
-1
+8
-14
-9
+1
+17
-11
-13
+10
+9
+17
-18
-1
+10
-7
+11
-3
+10
+1
+8
-7
+26
+17
-16
-12
+22
-16
+9
-17
-7
+3
+13
-18
+8
+6
+15
+19
+7
+7
-18
+15
+14
+3
+10
-3
+2
+8
+9
-6
+10
+1
+15
-3
-11
+5
-8
-15
+11
-3
-19
-15
-10
+12
-8
+7
+2
+8
+3
-18
+3
-2
-5
-7
+21
+4
-6
+1
+3
+15
-16
+24
+15
-16
-2
-11
+10
-11
+17
+15
+8
+11
+21
+5
+12
+13
-15
-16
-14
+2
-11
+14
-13
+12
-17
+6
-13
+9
-1
+20
-18
-18
-21
-6
+21
+13
-12
-15
-5
+39
+20
+13
+6
-1
+12
+1
-3
+14
-5
-3
+17
+12
-13
+18
+16
-12
-16
-9
+5
-7
-1
-17
-4
-8
+5
-13
+9
-19
+15
+13
-19
-15
-2
+14
-2
-8
+2
+15
-5
-13
+19
+21
+3
+11
-17
+12
+17
+19
-16
+17
+5
-10
+13
+3
-8
+18
-8
-9
-11
+5
-11
-10
-19
+7
-3
-7
-11
+26
-10
+16
+13
-10
+5
+7
-16
+22
-9
-6
+40
-13
+7
-9
+20
+7
+8
-6
+3
-10
-14
+10
-2
+15
-3
+2
+17
+4
+3
+13
+15
-8
+16
+9
-10
+7
+4
+9
-4
+1
-13
-1
+10
-19
+20
-8
-9
-6
-15
-8
+11
+17
+9
-7
-17
-7
+9
+4
-7
+6
+9
-13
-5
-8
+6
-2
-16
+10
-15
+7
+4
+3
-2
+6
-14
-12
-10
+11
-10
+2
-15
-6
+8
-6
-4
+22
-6
+17
+8
+6
-8
-4
-21
-7
+2
+9
-26
-6
+5
-20
-38
-4
-45
-15
+14
-3
-12
+22
+12
-15
+29
-95
-15
-3
+1
-31
-22
-17
-7
-15
-5
+2
-3
+15
+12
-5
-10
+1
+7
-6
+17
+2
+2
-19
-7
+15
-6
-7
-1
+7
-12
-6
-18
-14
+6
-4
-16
-13
+5
-13
+4
+16
-8
+13
+11
-2
-7
-5
-8
+1
+9
+6
-2
+19
-4
+5
+10
+2
-9
+10
-15
+7
+11
+6
-14
-11
-6
+3
-16
-19
-6
-3
-3
-11
+19
+16
-10
+14
+15
+2
+15
+21
+15
+7
+19
+2
+52
+13
+24
-32
-126
-18
+1
-17
-14
-14
+3
-19
-17
+13
+17
-20
-1
+17
+2
+14
-7
-8
+12
-1
-14
+1
+26
-14
-17
+3
-17
+13
-3
+5
-7
+20
-2
+24
+20
-13
-19
-22
-19
+12
+35
+5
+34
+8
+2
+11
-2
-1
+13
-9
-7
-2
-28
-33
-71491
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Day_02</RootNamespace>
</PropertyGroup>
</Project>
+124
View File
@@ -0,0 +1,124 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace Day_02
{
class Program
{
static void Main(string[] args)
{
//Part1();
Part2();
}
static void Part1()
{
int twiceCounter = 0;
int thriceCounter = 0;
var lines = File.ReadAllLines("input.txt");
foreach (var line in lines)
{
List<char> searchCharHistory = new List<char>();
int lineTwiceCounter = 0;
int lineThriceCounter = 0;
for (int i = 0; i < line.Length; i++)
{
char searchChar = line[i];
if(!searchCharHistory.Any(s => s == searchChar))
{
// If we haven't already counted this letter
int matchCharCount = line.Count(f => f == searchChar);
// Check if a letter appears twice (and increment the counter)
if (matchCharCount == 2) {
lineTwiceCounter += 1;
}
// Check if a letter appears three times (and increment the counter)
else if (matchCharCount == 3) {
lineThriceCounter += 1;
}
}
searchCharHistory.Add(searchChar);
}
if (lineTwiceCounter > 0) {
twiceCounter += 1;
}
if (lineThriceCounter > 0) {
thriceCounter += 1;
}
}
Console.WriteLine(twiceCounter);
Console.WriteLine(thriceCounter);
// multiply the two counters together
Console.WriteLine("The checksum is " + (twiceCounter * thriceCounter));
}
static void Part2()
{
bool endLoop = false;
var lines = File.ReadAllLines("input.txt");
// For each line of the input file
for (int i = 0; i < lines.Length; i++)
{
// Compare this line with each other line in the array
for (int j = 0; j < lines.Length; j++) {
if (CompareStrings(lines[i],lines[j])) {
// If it finds a string with just one letter wrong
endLoop = true;
break;
}
}
if (endLoop) {
break;
}
}
}
static bool CompareStrings(string string1, string string2)
{
if (string1 == string2) {
// Do nothing, it's the same string
}
// Split the characters of both strings into arrays
List<char> arr1 = new List<char>();
List<char> arr2 = new List<char>();
for (int ii = 0; ii < string1.Length; ii++) {
arr1.Add(string1[ii]);
}
for (int jj = 0; jj < string2.Length; jj++) {
arr2.Add(string2[jj]);
}
int wrongCharCounter = 0;
List<char> sameChars = new List<char>();
// For each letter in the first array, check if it corresponds to the appropriate letter in the second array
for (int kk = 0; kk < arr1.Count(); kk++) {
if (arr1[kk] != arr2[kk]) {
wrongCharCounter += 1;
}
else {
sameChars.Add(arr1[kk]);
}
}
if (wrongCharCounter == 1) {
Console.WriteLine("Common letters are: " + string.Join( ",", sameChars).Replace(",", ""));
return true;
}
else {
return false;
}
}
}
}
+23
View File
@@ -0,0 +1,23 @@
--- Day 2: Inventory Management System ---
You stop falling through time, catch your breath, and check the screen on the device. "Destination reached. Current Year: 1518. Current Location: North Pole Utility Closet 83N10." You made it! Now, to find those anomalies.
Outside the utility closet, you hear footsteps and a voice. "...I'm not sure either. But now that so many people have chimneys, maybe he could sneak in that way?" Another voice responds, "Actually, we've been working on a new kind of suit that would let him fit through tight spaces like that. But, I heard that a few days ago, they lost the prototype fabric, the design plans, everything! Nobody on the team can even seem to remember important details of the project!"
"Wouldn't they have had enough fabric to fill several boxes in the warehouse? They'd be stored together, so the box IDs should be similar. Too bad it would take forever to search the warehouse for two similar box IDs..." They walk too far away to hear any more.
Late at night, you sneak to the warehouse - who knows what kinds of paradoxes you could cause if you were discovered - and use your fancy wrist device to quickly scan every box and produce a list of the likely candidates (your puzzle input).
To make sure you didn't miss any, you scan the likely candidate boxes again, counting the number that have an ID containing exactly two of any letter and then separately counting those with exactly three of any letter. You can multiply those two counts together to get a rudimentary checksum and compare it to what your device predicts.
For example, if you see the following box IDs:
abcdef contains no letters that appear exactly two or three times.
bababc contains two a and three b, so it counts for both.
abbcde contains two b, but no letter appears exactly three times.
abcccd contains three c, but no letter appears exactly two times.
aabcdd contains two a and two d, but it only counts once.
abcdee contains two e.
ababab contains three a and three b, but it only counts once.
Of these box IDs, four of them contain a letter which appears exactly twice, and three of them contain a letter which appears exactly three times. Multiplying these together produces a checksum of 4 * 3 = 12.
What is the checksum for your list of box IDs?
+15
View File
@@ -0,0 +1,15 @@
--- Part Two ---
Confident that your list of box IDs is complete, you're ready to find the boxes full of prototype fabric.
The boxes will have IDs which differ by exactly one character at the same position in both strings. For example, given the following box IDs:
abcde
fghij
klmno
pqrst
fguij
axcye
wvxyz
The IDs abcde and axcye are close, but they differ by two characters (the second and fourth). However, the IDs fghij and fguij differ by exactly one character, the third (h and u). Those must be the correct boxes.
What letters are common between the two correct box IDs? (In the example above, this is found by removing the differing character from either ID, producing fgij.)
+250
View File
@@ -0,0 +1,250 @@
mphcuiszrnjzxwkbgdzqeoyxfa
mihcuisgrnjzxwkbgdtqeoylia
mphauisvrnjgxwkbgdtqeiylfa
mphcuisnrnjzxwkbgdgqeoylua
mphcuisurnjzxwkbgdtqeoilfi
mkhcuisvrnjzowkbgdteeoylfa
mphcoicvrnjzxwksgdtqeoylfa
mxhcuisvrndzxwkbgdtqeeylfa
dphcuisijnjzxwkbgdtqeoylfa
mihvuisvrqjzxwkbgdtqeoylfa
mphcuisrrnvzxwkbgdtqeodlfa
mphtuisdrnjzxskbgdtqeoylfa
mphcutmvsnjzxwkbgdtqeoylfa
mphcunsvrnjzswkggdtqeoylfa
mphcuisvrwjzxwkbpdtqeoylfr
mphcujsdrnjzxwkbgdtqeovlfa
mpfcuisvrdjzxwkbgdtteoylfa
mppcuisvrpjzxwkbgdtqeoywfa
mphcuisvrnjzxwkbfptqroylfa
mphcuisvrnjzxwkbgstoeoysfa
mphcufsvrnjzcwkbgdeqeoylfa
mphcuissrnjzxwkbgdkquoylfa
sphcuxsvrnjzxwkbgdtqioylfa
mphcuiivrhjzxwkbgdtqevylfa
echcuisvrnjzxwkbgltqeoylfa
mphcuisvrljexwkbvdtqeoylfa
mpjcuisvrnjzxwkhidtqeoylfa
mphcuisvrfjzmwkbgdtqeoylfl
mwhcuisvrnjzxwkbgdtqeoytfm
mphcuisvrsjzxwkbgdaqeoylfh
mohcuisvrnjzxwkbgdtqtoymfa
maycuisvrnjzxwkbgdtqboylfa
pphcuisvqnjzxwkbgdtqeoylfd
mprcuisvrnjtxwmbgdtqeoylfa
mfhcuisgrnjzxckbgdtqeoylfa
mphiubsvrnjzxwkbgdtqeoyufa
dphctisvrnjzxwkbgdtqeoylfk
mphcuisvrnjznwksgdtqeoyzfa
mpwcuisvrnjziwkbgdtqaoylfa
mphduzsvrnjznwkbgdtqeoylfa
mphccisvrnjzxwebgdtqeoylqa
xphcuisvrnjzxwkfvdtqeoylfa
mphcupsvrnjzxwkbgdtfeoylpa
mphcuisvrtjzjwkbgdtqeoylfe
mpbcuisvrnjzxwkbgdmieoylfa
mphcuisvrnjzxwkbgjtqetylaa
mphcuisvrnjzxwpbgdtgdoylfa
ophcufsvrqjzxwkbgdtqeoylfa
iphcuhsvrnjzxwkbgetqeoylfa
mphcuisvunjzxwwbgdtqeoylqa
mphcpisvrnjzowkbgdtveoylfa
mphcuisvrnjzxhkbgdtqeotlla
mphcuisvrnjzxwkbodtgeoylha
mphcuisvrjjzxwkbwdtqtoylfa
mphcwisvrnjnxwkbgjtqeoylfa
mplcuicqrnjzxwkbgdtqeoylfa
mphcuisvrnjzxydbgdtqeoylfn
ophckisvrnjzxwkbgdtqeozlfa
mphcuisvrkjzxwkbgdtteoblfa
yphcuisvrnjcxwkbggtqeoylfa
mphcuisvrnazxwfbqdtqeoylfa
mphcuisvrmjzxwkbgdtlwoylfa
mphctksvrnjzxwibgdtqeoylfa
mphcuisprnjzxlebgdtqeoylfa
mphcuisnrnjzxakbgdtueoylfa
mphcuiavrnjoxwtbgdtqeoylfa
nphcuisvrnjzxwkbgdtqzoylfk
mphcuisrrnjmxwkbgdtqdoylfa
mphcuisvrujzxwkvgdtqehylfa
mphcuisvrnfzxwkogdtqebylfa
mphcuisvrnjwdwkbgdtqeoyxfa
mphcuisvrntzxwkrgxtqeoylfa
mpzcuisvrnjzxwebgdtqeoylsa
aphcuikvrnjzxwwbgdtqeoylfa
mphcqisvrnjzxwkpgdtqeoelfa
mphcuusvrnjzxwkbgdtjeodlfa
mphcuisvrnjzewkbgdtteoylza
mphcuisvanjzxwkbgdtheoylfc
mphcjishrnjzxwkbgltqeoylfa
mpxcuislrnjzxwkbgdtqeoynfa
mphcuisvrnjjxwkbgdtmeoxlfa
mphcimsvrnjzxwkbsdtqeoylfa
mphcxisvcnjzxwjbgdtqeoylfa
mphcuisbrvjzxwkbgdtqeoymfa
mplcuisvrnjzxwkbgdtaenylfa
mphcuihvrnjzxwkygytqeoylfa
mphcbisvrnjzxhkbgdtqezylfa
mphcuisarnjzxwkbgatqeoylfv
mphcumsvrnjzxwkbgdrqebylfa
mlhcuisvrnwzxwkbgdtqeoylfx
mpkcuisvrkjzxwkbgdtqeoylfo
mphcuissrnjzxwkbgdtqmoylfc
mphcuiwvrnjuxwkfgdtqeoylfa
mphcuicvlnjzxwkbgdvqeoylfa
mphcuisvrvvzxwkbfdtqeoylfa
myhcuisvrnjpxwkbgntqeoylfa
mpocuisvrnjzxwtbgitqeoylfa
mphcuisvrnjzxwkbgdtwewyqfa
mphcuisvtnjzxwwbgdtqeoolfa
mphcuisvrnjzxgkbgdyqeoyyfa
mphcuisvrdjzxwkbgpyqeoylfa
bphcuisvrnjzxwkbgxtqefylfa
sphcuisvrdjzxwktgdtqeoylfa
mphcuvsvrnjmxwobgdtqeoylfa
mphcuisvrnjzxwkbsdtqeuylfb
mnhcmisvynjzxwkbgdtqeoylfa
mphckisvrnjzxwkhgdkqeoylfa
mpacuisvrnjzxwkbgdtqeoolaa
mpgcuisvrnjzxwkbzdtqeoynfa
mphcuisvrojzxwkbzdtqeoylga
mphcuisvknjfxwkbydtqeoylfa
mphcuistrnjzxwkbgdqqeuylfa
bpvcuiszrnjzxwkbgdtqeoylfa
mphcuxsvrnjzswkbgdtqeoelfa
mphcuisvbnjzxwlbgdtqeoylla
mphcuisvonczxwkbgktqeoylfa
mphcuisvrnkzxwvbgdtquoylfa
mphcuisvrnjzxokfgdtqeoylia
tphcuisvrnjzxwkbjdwqeoylfa
mihcuisvrnjzpwibgdtqeoylfa
mphcuisvrejzxwkbgdtqjuylfa
mprcuisvrnjixwkxgdtqeoylfa
mpqcuiszrnjzxwkbgdtqeodlfa
mphcuasvrnjzzakbgdtqeoylva
mphcuisvrnjzmwkbtdtqeoycfa
mphcuisvrnjzxwkbcdtqioylxa
mphckisvrnjzxwkbcdtqeoylfm
mphcuisvrnjuxwbogdtqeoylfa
mphcuisdrnjzxwkbldtqeoylfx
mphcuisvrnjoxwkbgdtqeyyyfa
mphcuicvqnjzxwkbgdtqeoylna
mpmcuisvrnjzxwkbgdtqktylfa
mphcuisvrnqzxwkggdtqeoykfa
mphcuisvryjzxwkbydtqejylfa
mphcugsvrnjzxwkbghtqeeylfa
rphcuusvrnjzxwkwgdtqeoylfa
zphwuiyvrnjzxwkbgdtqeoylfa
cphcuivvrnjzxwkbgdtqenylfa
mphcuisvrnjzxwkagotqevylfa
mprcuisvrcjzxwkbgdtqeoytfa
mphjugsvrnezxwkbgdtqeoylfa
mphcuisvryjzxwkbgltqeoylaa
mphcursvrnjzxfkbgdtqeoydfa
mphcuisvrcuzxwkbgdtqeoylfw
mphcuisvrijzxwkbgdtqeoelfh
xphcuisvenjzxjkbgdtqeoylfa
mphcuisvrnazxwkbgdeqeoylaa
mphcuisbrsjzxwkbgdtqeoygfa
mlhvuisvrnjzxwkbgdtqeoylfh
mphcuisvrnjzxukbgdtqeoyhfy
mpzcuilvrnjzawkbgdtqeoylfa
hphcuisjfnjzxwkbgdtqeoylfa
mahcuisvrnjzxwkegdtqeoylfi
mphcuixvrnjzcwkbgdtqetylfa
mphcuisvrnjzxwkdgdtqeoklfj
mlhcuisvrnjzxwkbgdteeoylka
mphcuifvrnjbxwkrgdtqeoylfa
mphcuasvrnjzzwkbgdtqeoylva
mphcuisvrnjzxwkboutqeoylba
mbhcuisvcnjzxwklgdtqeoylfa
mpbcuisvrnjzxgkbgdtqesylfa
mphcuisvrnjfswkbgdtqeoylfd
mphcuisvrnjzxwkbgdoweoysfa
uphcuisvrnjzrwkbgdtqelylfa
mphcuisvrnjzxwkbgdtqyoylsi
mpqcuiqvxnjzxwkbgdtqeoylfa
mphcuisorfjzxwkbgatqeoylfa
mphcuisvrntfxwkbzdtqeoylfa
mphcuisvrnrzxwkbgdtueoylfl
mphcuisvrnjzewkagdtyeoylfa
mpocuisdrnjzxwkbgdtqeozlfa
mphcuisvrnjjxwkbgdtoeoylfm
mphcuisvenjzxwkbgdtqwoylza
mpmcuisvrnjzxwkbgdtqeoxlfr
mphcuisvgnjhxwkbgdtqeoplfa
mphcuisvrnjzowkdgdtqeoyyfa
mphcuisqynjzxwkbgdtqeoylda
hphcuisvgnjzxwkbgdtbeoylfa
iphcuipvrnuzxwkbgdtqeoylfa
mphcuisvrnjzsikbpdtqeoylfa
mpwcuhsvrnjzxbkbgdtqeoylfa
mnhjuisvcnjzxwkbgdtqeoylfa
mphcudsvrnjzxwkbgdtqloilfa
mpncuiwvrwjzxwkbgdtqeoylfa
mphcuisvrnjgawkbgdtqeoylya
mphcuisvrnjzxwkbggtteoslfa
mphcuisvrnjzxwkbgdvqeoylpe
mphcuisvrnczxfkbgktqeoylfa
mphcuifvrnjzxwkbgdbmeoylfa
mphcuisvrnjytwkbgdtqeoylla
mphcuisvrnjzxwkbgdtjeoxlfn
mphjuisvrnjzxwkbghtqeoyffa
mphcuisvrnjzxkrbgdtqeoylaa
mphcbisvrnjzxwkbgttqeoylfs
mphkuksvbnjzxwkbgdtqeoylfa
nphcuidvrnjzxwhbgdtqeoylfa
mphguzsvrnjzxwkbgdaqeoylfa
mihcuisfrnjzxwkbgdtqhoylfa
mphcuisvrnrzxwpbgdtqesylfa
zphcuisvrnjzxwkbddtqeoylaa
mphcuigvmnjzxwkbgdtqeoylba
mjhcuisvrnjzxjkbgdtqeoylha
mphnuisvrnjznwkbgdtqnoylfa
mkhcuisvrnjcxwkbgdqqeoylfa
mphcuisvenjzxwbbqdtqeoylfa
qphcuisnrnjzawkbgdtqeoylfa
mphcuisvrdjzxwkbgdtqeoywca
mphcuzsvvnjzxwfbgdtqeoylfa
pphcuxsvrnjzxwkbgdtmeoylfa
mphiuvsvrnjzxlkbgdtqeoylfa
mphlqisvrnjzxkkbgdtqeoylfa
mmhcuisvrnjzxwkbgatqeoylea
mphduisrrnjoxwkbgdtqeoylfa
mphcuisvrnjnxwkvgdyqeoylfa
mphcuvsvrnjzxgkbgdtqeoylfz
mphcuisvryjzxwkbggtqkoylfa
iphcuisvrdjzxwkbgotqeoylfa
mphcuisvrnjzxwhbgdtqwoyofa
mphcorbvrnjzxwkbgdtqeoylfa
mghcuisvrnpzxykbgdtqeoylfa
mphauisvrnjnxwkbzdtqeoylfa
mphcgisvrnjzxwkwgdtqeoygfa
mphcuisvrnjzxwkggotqeoylba
mphcuesvrnjzxwkbgdwqebylfa
yphcuisvrnjzxwkbgdxqeoylja
ephyuisvrnjzywkbgdtqeoylfa
mfhcuisqrnjzxwkbgdlqeoylfa
mphkuisvrnjzxwkbertqeoylfa
mphcuusgrnjzxwkbggtqeoylfa
mphcuildrnjvxwkbgdtqeoylfa
mphcuiuvrnjzlwkbgwtqeoylfa
mppcuisvrljzxwkbgdtqeoylfw
mphcwiwvrnjzxwsbgdtqeoylfa
mphcubivrnjzxwkqgdtqeoylfa
mphcuisvrnjpxwkngdtqeoylpa
pchcuisvrgjzxwkbgdtqeoylfa
mphcuisvlnjzxwkbgdtmeoylfw
mphcuisvrnjzywkbgdvqeoylfj
mpzcuisvrnezxwktgdtqeoylfa
mphcuisvrnjbxwkbgzrqeoylfa
mphcuisvrnjzxwktgdtqeodtfa
jphcuiavrnjzxwkbgdtqeoylfv
mphcuisvrnjzxwkbddppeoylfa
mphcuissrkjzxwkbgxtqeoylfa
mphcuisvrhjzxwxbgdtqeoylxa
mphcvisvgnjjxwkbgdtqeoylfa
mphcuisprnjwxwtbgdtqeoylfa
mphcuissrnjzxqkbgdtqeoymfa
mphcuiabrnjzxokbgdtqeoylfa
mphcuisvrnczxwkbgmtpeoylfa
+11
View File
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
namespace Day_03
{
public class Claim
{
public int ClaimId { get; set; }
public bool CellsUsedMoreThanOnce { get; set; }
}
}
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Day_03</RootNamespace>
</PropertyGroup>
</Project>
+128
View File
@@ -0,0 +1,128 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Day_03
{
class Program
{
static void Main(string[] args)
{
// Declare an empty 2D array with 1000x1000 cells, material[x,y] from left and top respectively
int[,] material = new int[1000, 1000];
List<Claim> claims = new List<Claim>();
var lines = File.ReadAllLines("input.txt");
// For each line of the input file
foreach (var line in lines)
{
// A claim like #123 @ 3,2: 5x4 means that claim ID 123 specifies a rectangle 3 inches from the left edge, 2 inches from the top edge, 5 inches wide, and 4 inches tall.
// Remove the id number and everything prior to the left edge measurement
int startIndex = line.IndexOf("@") + 1;
int endIndex = line.Length;
var lineData = line.Substring(startIndex, endIndex - startIndex);
// Store all the data
Regex re1 = new Regex(@"(@ [0-9]+,)");
var leftPositionList = re1.Matches(line);
string leftPosition = leftPositionList[0].Value.Substring(2, leftPositionList[0].Value.Length -1 - 2);
Regex re2 = new Regex(@"(,[0-9]+:)");
var topPositionList = re2.Matches(line);
string topPosition = topPositionList[0].Value.Substring(1, topPositionList[0].Value.Length -1 - 1);
Regex re3 = new Regex(@"(: [0-9]+x)");
var widthList = re3.Matches(line);
int width = Int32.Parse(widthList[0].Value.Substring(1, widthList[0].Value.Length -1 - 1));
Regex re4 = new Regex(@"(x[0-9]+)");
var lengthList = re4.Matches(line);
int length = Int32.Parse(lengthList[0].Value.Substring(1));
// Store data in all cells horizontally and vertically
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
// Store a count of how many times the cell is used at the appropriate co-ordinates
material[(Int32.Parse(leftPosition) + i), (Int32.Parse(topPosition) + j)] += 1;
}
}
}
// Part 1
// Loop through both arrays and count how many cells have a recorded overlap
int overlapCounter = 0;
for(int i = 0; i < 1000; i++){
for(int j = 0; j < 1000; j++){
if(material[i, j] > 1){
overlapCounter += 1;
}
}
}
Console.WriteLine(material[0, 0]);
Console.WriteLine(material.Length);
Console.WriteLine("The number of overlapping square inches is " + overlapCounter);
// Part 2
// Loop through all claims (lines in the file) and find the one where the material is only used once in every cell
// For each line of the input file
foreach (var line in lines)
{
var claim = new Claim();
// A claim like #123 @ 3,2: 5x4 means that claim ID 123 specifies a rectangle 3 inches from the left edge, 2 inches from the top edge, 5 inches wide, and 4 inches tall.
// Remove the id number and everything prior to the left edge measurement
int startIndex = line.IndexOf("@") + 1;
int endIndex = line.Length;
var lineData = line.Substring(startIndex, endIndex - startIndex);
// Store all the data
Regex re0 = new Regex(@"(#(\d+))");
var claimIdList = re0.Matches(line);
string claimId = claimIdList[0].Value.Substring(1);
claim.ClaimId = Int32.Parse(claimId);
Regex re1 = new Regex(@"(@ [0-9]+,)");
var leftPositionList = re1.Matches(line);
string leftPosition = leftPositionList[0].Value.Substring(2, leftPositionList[0].Value.Length -1 - 2);
Regex re2 = new Regex(@"(,[0-9]+:)");
var topPositionList = re2.Matches(line);
string topPosition = topPositionList[0].Value.Substring(1, topPositionList[0].Value.Length -1 - 1);
Regex re3 = new Regex(@"(: [0-9]+x)");
var widthList = re3.Matches(line);
int width = Int32.Parse(widthList[0].Value.Substring(1, widthList[0].Value.Length -1 - 1));
Regex re4 = new Regex(@"(x[0-9]+)");
var lengthList = re4.Matches(line);
int length = Int32.Parse(lengthList[0].Value.Substring(1));
// Store data in all cells horizontally and vertically
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
// Check how many times the cell has been used at the appropriate co-ordinates
// If it has been used more than once, set CellsUsedMoreThanOnce to true
if (material[(Int32.Parse(leftPosition) + i), (Int32.Parse(topPosition) + j)] > 1)
{
claim.CellsUsedMoreThanOnce = true;
}
}
}
claims.Add(claim);
}
// Find the only claim that has no overlap
int finalClaimId = claims.First(c => !c.CellsUsedMoreThanOnce).ClaimId;
Console.WriteLine("The ID of the only claim that doesn't overlap is: " + finalClaimId);
}
}
}
+40
View File
@@ -0,0 +1,40 @@
--- Day 3: No Matter How You Slice It ---
The Elves managed to locate the chimney-squeeze prototype fabric for Santa's suit (thanks to someone who helpfully wrote its box IDs on the wall of the warehouse in the middle of the night). Unfortunately, anomalies are still affecting them - nobody can even agree on how to cut the fabric.
The whole piece of fabric they're working on is a very large square - at least 1000 inches on each side.
Each Elf has made a claim about which area of fabric would be ideal for Santa's suit. All claims have an ID and consist of a single rectangle with edges parallel to the edges of the fabric. Each claim's rectangle is defined as follows:
The number of inches between the left edge of the fabric and the left edge of the rectangle.
The number of inches between the top edge of the fabric and the top edge of the rectangle.
The width of the rectangle in inches.
The height of the rectangle in inches.
A claim like #123 @ 3,2: 5x4 means that claim ID 123 specifies a rectangle 3 inches from the left edge, 2 inches from the top edge, 5 inches wide, and 4 inches tall. Visually, it claims the square inches of fabric represented by # (and ignores the square inches of fabric represented by .) in the diagram below:
...........
...........
...#####...
...#####...
...#####...
...#####...
...........
...........
...........
The problem is that many of the claims overlap, causing two or more claims to cover part of the same areas. For example, consider the following claims:
#1 @ 1,3: 4x4
#2 @ 3,1: 4x4
#3 @ 5,5: 2x2
Visually, these claim the following areas:
........
...2222.
...2222.
.11XX22.
.11XX22.
.111133.
.111133.
........
The four square inches marked with X are claimed by both 1 and 2. (Claim 3, while adjacent to the others, does not overlap either of them.)
If the Elves all proceed with their own plans, none of them will have enough fabric. How many square inches of fabric are within two or more claims?
+6
View File
@@ -0,0 +1,6 @@
--- Part Two ---
Amidst the chaos, you notice that exactly one claim doesn't overlap by even a single square inch of fabric with any other claim. If you can somehow draw attention to it, maybe the Elves will be able to make Santa's suit after all!
For example, in the claims above, only claim 3 is intact after all claims are made.
What is the ID of the only claim that doesn't overlap?
File diff suppressed because it is too large Load Diff
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace Day_04
{
public class Action
{
public string Date { get; set; }
public string Time { get; set; }
public string Description { get; set; }
}
}
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Day_04</RootNamespace>
</PropertyGroup>
</Project>
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace Day_04
{
public class Day
{
public string Date { get; set; }
public int GuardId { get; set; }
public List<bool> IsAsleepThisMinute { get; set; }
}
}
+12
View File
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace Day_04
{
public class Guard
{
public int GuardId { get; set; }
public int TotalMinutesAsleep { get; set; }
public List<int> TimesSleptPerMinute { get; set; }
}
}
+81
View File
@@ -0,0 +1,81 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Day_04
{
class Program
{
static void Main(string[] args)
{
// Find the guard that has the most minutes asleep.
// What minute does that guard spend asleep the most?
// Make an empty list of guards
List<Guard> guards = new List<Guard>();
// Take in an unordered list of times and dates when guards start shifts, fall asleep and wake up
var lines = File.ReadAllLines("input.txt");
// Sort that into an ordered list, by date then time
List<Action> actions = new List<Action>();
foreach (var line in lines)
{
Action action = new Action();
Regex re1 = new Regex(@"((\d\d\d\d-\d\d-\d\d))");
var dateString = re1.Matches(line)[0].Value;
action.Date = dateString.Substring(0, dateString.Length);
Regex re2 = new Regex(@"((\d\d:\d\d))");
var timeString = re2.Matches(line)[0].Value;
action.Time = timeString.Substring(0, timeString.Length);
Regex re3 = new Regex(@"(\] (.*))");
Match match3 = re3.Match(line);
action.Description = match3.Groups[2].Value;
actions.Add(action);
}
actions = actions.OrderBy(a => a.Date).ThenBy(a => a.Time).ToList();
// Use the ordered list to create a list of days with the guard id and a breakdown of minutes slept and awake
List<Day> days = new List<Day>();
foreach (var action in actions)
{
Day day = new Day();
if(days.Any(d => d.Date == action.Date))
{
day = days.First
}
day.Date = action.Date;
Regex re1 = new Regex(@"(#(\d+))");
Match match1 = re1.Match(action.Description);
if (match1.Success)
{
day.GuardId = Int32.Parse(match1.Groups[2].Value);
}
else
{
// Use the ID from a previous action on the same day
day.GuardId = days.First(d => d.Date == day.Date).GuardId;
}
// Date
// GuardId
// IsAsleepThisMinute
}
// Use the list of days to populate the list of guards
}
}
}
+49
View File
@@ -0,0 +1,49 @@
--- Day 4: Repose Record ---
You've sneaked into another supply closet - this time, it's across from the prototype suit manufacturing lab. You need to sneak inside and fix the issues with the suit, but there's a guard stationed outside the lab, so this is as close as you can safely get.
As you search the closet for anything that might help, you discover that you're not the first person to want to sneak in. Covering the walls, someone has spent an hour starting every midnight for the past few months secretly observing this guard post! They've been writing down the ID of the one guard on duty that night - the Elves seem to have decided that one guard was enough for the overnight shift - as well as when they fall asleep or wake up while at their post (your puzzle input).
For example, consider the following records, which have already been organized into chronological order:
[1518-11-01 00:00] Guard #10 begins shift
[1518-11-01 00:05] falls asleep
[1518-11-01 00:25] wakes up
[1518-11-01 00:30] falls asleep
[1518-11-01 00:55] wakes up
[1518-11-01 23:58] Guard #99 begins shift
[1518-11-02 00:40] falls asleep
[1518-11-02 00:50] wakes up
[1518-11-03 00:05] Guard #10 begins shift
[1518-11-03 00:24] falls asleep
[1518-11-03 00:29] wakes up
[1518-11-04 00:02] Guard #99 begins shift
[1518-11-04 00:36] falls asleep
[1518-11-04 00:46] wakes up
[1518-11-05 00:03] Guard #99 begins shift
[1518-11-05 00:45] falls asleep
[1518-11-05 00:55] wakes up
Timestamps are written using year-month-day hour:minute format. The guard falling asleep or waking up is always the one whose shift most recently started. Because all asleep/awake times are during the midnight hour (00:00 - 00:59), only the minute portion (00 - 59) is relevant for those events.
Visually, these records show that the guards are asleep at these times:
Date ID Minute
000000000011111111112222222222333333333344444444445555555555
012345678901234567890123456789012345678901234567890123456789
11-01 #10 .....####################.....#########################.....
11-02 #99 ........................................##########..........
11-03 #10 ........................#####...............................
11-04 #99 ....................................##########..............
11-05 #99 .............................................##########.....
The columns are Date, which shows the month-day portion of the relevant day; ID, which shows the guard on duty that day; and Minute, which shows the minutes during which the guard was asleep within the midnight hour. (The Minute column's header shows the minute's ten's digit in the first row and the one's digit in the second row.) Awake is shown as ., and asleep is shown as #.
Note that guards count as asleep on the minute they fall asleep, and they count as awake on the minute they wake up. For example, because Guard #10 wakes up at 00:25 on 1518-11-01, minute 25 is marked as awake.
If you can figure out the guard most likely to be asleep at a specific time, you might be able to trick that guard into working tonight so you can have the best chance of sneaking in. You have two strategies for choosing the best guard/minute combination.
Strategy 1: Find the guard that has the most minutes asleep. What minute does that guard spend asleep the most?
In the example above, Guard #10 spent the most minutes asleep, a total of 50 minutes (20+25+5), while Guard #99 only slept for a total of 30 minutes (10+10+10). Guard #10 was asleep most during minute 24 (on two days, whereas any other minute the guard was asleep was only seen on one day).
While this example listed the entries in chronological order, your entries are in the order you found them. You'll need to organize them before they can be analyzed.
What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 10 * 24 = 240.)
File diff suppressed because it is too large Load Diff