bit behind, so much work

This commit is contained in:
Benjamin Kyd
2020-12-06 00:31:14 +00:00
parent 7e353fc760
commit 77ecdee0f8
66 changed files with 12636 additions and 11133 deletions

View File

@@ -1,42 +1,42 @@
{
"files.associations": {
"cmath": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
{
"files.associations": {
"cmath": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}

View File

@@ -1,25 +1,25 @@
--- Day 1: Chronal Calibration ---
"We've detected some temporal anomalies," one of Santa's Elves at the Temporal Anomaly Research and Detection Instrument Station tells you. She sounded pretty worried when she called you down here. "At 500-year intervals into the past, someone has been changing Santa's history!"
"The good news is that the changes won't propagate to our time stream for another 25 days, and we have a device" - she attaches something to your wrist - "that will let you fix the changes with no such propagation delay. It's configured to send you 500 years further into the past every few days; that was the best we could do on such short notice."
"The bad news is that we are detecting roughly fifty anomalies throughout time; the device will indicate fixed anomalies with stars. The other bad news is that we only have one device and you're the best person for the job! Good lu--" She taps a button on the device and you suddenly feel like you're falling. To save Christmas, you need to get all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
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
--- Day 1: Chronal Calibration ---
"We've detected some temporal anomalies," one of Santa's Elves at the Temporal Anomaly Research and Detection Instrument Station tells you. She sounded pretty worried when she called you down here. "At 500-year intervals into the past, someone has been changing Santa's history!"
"The good news is that the changes won't propagate to our time stream for another 25 days, and we have a device" - she attaches something to your wrist - "that will let you fix the changes with no such propagation delay. It's configured to send you 500 years further into the past every few days; that was the best we could do on such short notice."
"The bad news is that we are detecting roughly fifty anomalies throughout time; the device will indicate fixed anomalies with stars. The other bad news is that we only have one device and you're the best person for the job! Good lu--" She taps a button on the device and you suddenly feel like you're falling. To save Christmas, you need to get all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
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?

View File

@@ -1,3 +1,3 @@
const fs = require('fs');
let input = fs.readFileSync('input.txt').toString().split('\n').join('');
console.log(eval(input));
const fs = require('fs');
let input = fs.readFileSync('input.txt').toString().split('\n').join('');
console.log(eval(input));

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,21 @@
--- Part Two ---
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.
--- Part Two ---
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?

View File

@@ -1,24 +1,24 @@
const fs = require('fs');
let input = fs.readFileSync('input.txt')
.toString()
.split('\n')
.map((x) => parseInt(x));
let seenFrequencies = new Set([0]);
let total = 0;
let i = 0;
while (true) {
if (i === input.length) {
i = 0;
continue;
}
total += input[i];
if (seenFrequencies.has(total)) {
break;
}
seenFrequencies.add(total);
i++;
}
console.log(total)
const fs = require('fs');
let input = fs.readFileSync('input.txt')
.toString()
.split('\n')
.map((x) => parseInt(x));
let seenFrequencies = new Set([0]);
let total = 0;
let i = 0;
while (true) {
if (i === input.length) {
i = 0;
continue;
}
total += input[i];
if (seenFrequencies.has(total)) {
break;
}
seenFrequencies.add(total);
i++;
}
console.log(total)

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +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.
--- 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?

View File

@@ -1,250 +1,250 @@
ybruvapdgixszyckwtfqjonsie
mbruvapxghslyyckwtfqjonsie
mbruvapdghslzyckwtkujonsie
rwruvapdghxlzyckwtfqjcnsie
obruvapdgtxlzyckwtfqionsie
lbruvapdghxqzyckwtfqjfnsie
mbrunapdghxlzyccatfqjonsie
mbruvapdghxlzyokltfqjdnsie
ybruvapdghxlzmckwtfqjmnsie
mbruwaadghxdzyckwtfqjonsie
muruvapdghxlzyckvtfqjonsim
mbruvapdghxlkyckwtxqjonjie
mbruvaqdghxlzyckwtfqjrnnie
mwruvapdghdlzyckttfqjonsie
mbruvapdgtelzyckwxfqjonsie
mbruvapdohxlzvckwtfqjonhie
mbrugapdgbxlzyckwtfqjynsie
mbruvapdghxlzyckwtlqjonjiu
mbruvapwghxlzyckwafqjonbie
wbruvapdghxlhyckwtfqjonsii
mbruvapdghxlzyckwtcqnonsiq
mbyuvapighxlzybkwtfqjonsie
mbrrvapdghxvzyckwtfqjonsio
mhruvapdghrlzyckwtfzjonsie
mtruvapvghxlzyckwtfnjonsie
mmrlhapdghxlzyckwtfqjonsie
mbruvapdgpxlzyjkwtfqjovsie
mbrucapdghxlzymkwtzqjonsie
mbeuvafdghxlzyckwtfqjonwie
mbruvapcghxlayckwtfqjonsii
mbruvabdghxlzyckwtfqyansie
mbruvjpdghxlzyckwtfqgfnsie
lbruvapdghxlzyckwtfqjonriv
mbrupapdghxlzycjwtfqronsie
mbpuvapdthxlzymkwtfqjonsie
mbiuvapdgixlzyckwxfqjonsie
mbruvapdghxyzyckwtfcjonsbe
mbrurapkghxlzyckwtfqjonzie
mbrufapdrhxlzyciwtfqjonsie
mbruvapdghxlzbckwtfqjoisae
ubruhapdghxlzuckwtfqjonsie
mbruvapdjhulzyckwtfqjonshe
mbruwapdgyxlzyckntfqjonsie
mwruvapdghplzyckwtfqjonsme
mbruvapjghtlzyckwtfqgonsie
pbruvapdghhlzyckwtfrjonsie
mbruvgpdihxqzyckwtfqjonsie
mbruvahdohxlzyckwtfijonsie
ibuuvapdghxlzyckwtfqjofsie
mbruvandghxlzyckwtfqjrnxie
mbrjvlpdghxlzyckwgfqjonsie
mbruvapogfxlzyckotfqjonsie
mbruvrpdghxlzyckutfejonsie
mbruvbpdghxlzyhkwtfqjonsip
mbruvapdghxlzyckmnfqjensie
mbruvapdghvlzyckwtfqjowsix
mbruvakdgholzwckwtfqjonsie
mbruvapdghxlzackwtfqconsae
mbruvapdghxlzyqvwtfqjlnsie
mprrvapdgfxlzyckwtfqjonsie
mbrunacdghxlhyckwtfqjonsie
obruvapdgsxlzyckwtfqjonvie
murcvapdghslzyckwtfqjonsie
mbruvapdghxlzyzkwmftjonsie
mbrwvapdgtvlzyckwtfqjonsie
mbxuvapdghxlzqcnwtfqjonsie
mbruvaddghxboyckwtfqjonsie
mhruvwndghxlzyckwtfqjonsie
mbrdvapdghxlzyckwmpqjonsie
mbruvapdgyxlzyckizfqjonsie
mbruvapdghxlzlckwtfqeowsie
mbruvbpdgrxlzyckwtfqjonsxe
mbruqapoghxlzyckwtvqjonsie
mbouhapdghmlzyckwtfqjonsie
mbruvapjghxidyckwtfqjonsie
mbsuvapkghxlkyckwtfqjonsie
mbruvlpdghxlzycrwtfqjonsis
mcrueapdghxlzyckwtfqjynsie
muruvapngbxlzyckwtfqjonsie
mbruvapdghxlzycawtfyjojsie
mbruvbpdghxczyjkwtfqjonsie
ybduvapdghxnzyckwtfqjonsie
mbruvbpdghxlzyckwtfbjousie
mbouvapdghxlzycbwtfqponsie
mbruvaedghplzycgwtfqjonsie
mbrhvapdghxlzyckytfqjgnsie
mbruvapdqbxleyckwtfqjonsie
mbruvapddhhldyckwtfqjonsie
mbruvapdghxlwrckwtfqjondie
mbruvapdmhxlzyckwtfqkonsve
xbbuvapdghxlzyckwtfkjonsie
mbruvapdghxlzyckwcfqjunkie
mbruvapdghxlzyckwtfqxonfib
mbrtvapkghxlzyckwtfqeonsie
mbruvazdghxldymkwtfqjonsie
kbruvapddhxlzfckwtfqjonsie
mbouvapdghxlpyckwtfqjoosie
mbauvapdghxlzyckwtfqjszsie
mbruvapdghtlzyckntfqtonsie
mbruvipdggxlzbckwtfqjonsie
mbruqapdghrlzyckwtfqjznsie
myruvacdghxlzyckwifqjonsie
mbruvapdghxlzuckwtfkjocsie
mwjuvapdghxlzyckwtfqjonsxe
mbruvapxghxlzickwtfqjobsie
mbrupapdghxtlyckwtfqjonsie
meruvapdjjxlzyckwtfqjonsie
mbruvkodghxlzyckwofqjonsie
mbruvapdgexlzyckwtgkjonsie
mbruvapwghxlzyckwtcqjonsiw
mbruvapdghxlzykkwtfqtoxsie
mbruvapdahxlzycgwtfwjonsie
mbruvapdgwxlhyckhtfqjonsie
mbruvapbghxlzycbhmfqjonsie
mbruvapdghxvzyzkwtfqjonsin
mbrcvapdqhxlzyckwyfqjonsie
zbruvaxdghxlzyckwgfqjonsie
mtruvapdghxlilckwtfqjonsie
bbruvapdghxlzyckwtfmjonsxe
mbruvajdghxlzyckwtfqfwnsie
mbruvapdgkxlzyckwtfqionpie
rbruvapdghxlryckwdfqjonsie
mbruvandghxlzyckwmfvjonsie
mbruvahdghxlzeckwtfqjonsme
mbruvnpcghxlzyckwtfqjobsie
mbruvapdghqlzyckwtfbjonsiy
mbruvavdghxlzyckwufqjodsie
mbruvapdghxlzyckwtfzmovsie
mbruvlpdghxuzyckwtfqjoesie
mbruvopdghxlzycwwtfqjansie
obruvapdghglzybkwtfqjonsie
mbpuvlpdghxlcyckwtfqjonsie
mbruvaidghxlzyckwtfmjonoie
mbruvapdihxzzyckwtfqjonsiy
mbquvapdghxlzyckwtfqconsme
mbruvapdghslzyckqtfqjojsie
mbrzdapdghxmzyckwtfqjonsie
mwruvapdghxozyckwtfqjonsxe
muruvapdgfxlzyckwtfqjojsie
wtruvapdghxlzyckvtfqjonsie
mbruvapdghxlzyckysfqjxnsie
mbruvrpdghxczyckktfqjonsie
mbquvapdghxlryckwtfqjonsne
mbruvapdghflzycvwtfqjpnsie
mbruvapughclzyckwtfqjonsin
mbrhvapdghxlpyckwtfqjonsre
mbruvapdgtxlzyckwtfqjoosit
mbrupapnghxhzyckwtfqjonsie
mmvuvapdvhxlzyckwtfqjonsie
mbruvaptghxlzyckwtfqjotsse
mgruvapvghxlzyckwtfqjonsix
mbrupapdghxszyckwtfqjunsie
mbruvkpdghelzyckwtfqjpnsie
mbruvrrdghjlzyckwtfqjonsie
mbruvapdghnlzyckwtfkjonsze
mbruvwpdghxlzyckwtfqhoysie
mbrsvapdfhxlzyckwtfqjobsie
mbruvapdgexezymkwtfqjonsie
ybruvapdghxlzyckwtfqxonsiw
mrruvapdghxdzyckwtfqjossie
mbruvapdghtlzyckwtfqconsiu
mbrpvapdghxlzlckwpfqjonsie
mbruvjpdghslzyckwtfqjjnsie
mhruvapoghxlzyckwtfvjonsie
mbrubqpdghvlzyckwtfqjonsie
mbruvapdghxlzackwtfqconsiw
mbruvapdgnxlzkckwtfqjdnsie
mbrudapgghelzyckwtfqjonsie
mbruvapdghxlzlakwbfqjonsie
mbpuvapdghxlzyckwtuqjonjie
abruvapdghxlzykkwtfqjonzie
mbrupupdghxlsyckwtfqjonsie
mbrsvupdghxlzyckwtfqjonkie
mxruvgpdghxllyckwtfqjonsie
mbrnvapdghxlzycbwtfqfonsie
mbrbxapdghxlzyckttfqjonsie
mbnuvapdghxlzyxkwtmqjonsie
mbrfvapdghjlzickwtfqjonsie
mbhuvupdghxlzyxkwtfqjonsie
mbrcvapdghxluyckwtfqjznsie
mbruvapdghxlzyckwofqjoxsiz
mbrevapdghxloyckwtfqjonnie
mbruvipdghnlzyckwtfqjopsie
mbxxvaptghxlzyckwtfqjonsie
mbruvcpdghxlztckwtjqjonsie
mqruvlpdghxlzyckotfqjonsie
mbruvapdgqxlzyckwtfqjpvsie
mbruvapdgvxlzyjkwtfqjbnsie
mbruvapdghxlgyckwtfqcocsie
mbruvapdghxkwyckwtfqjoqsie
mbrgvavdghxlzyckwxfqjonsie
qbruqapdgvxlzyckwtfqjonsie
mbauvapdghxlzgckwtfqjunsie
mbruvapdgdxluyckwtfqjoosie
mbruvapdghxlzykkwtfqwobsie
mbruvapdghxlzhcnwtfqjonqie
mbruvapdghxlzycbhmfqjonsie
mbruvapdghxluyczwtfqjontie
mbruvapnghxlzyckwnfqjonbie
moruvapdghxlzcckwtfqponsie
mbruvapfgxxlzyckwtfqjunsie
mbruvapdghxlryckvtfejonsie
mbrzvapdghxlzvcbwtfqjonsie
mbruvapdgqxlzyckwcfqjonsce
abruvupdrhxlzyckwtfqjonsie
mbrubaptghxlzyckwtfqjondie
mgruvapdgpxlzyckwtfijonsie
mbruvapdghxczlckwtfujonsie
mbruvapdgmmlzyckwtfqjonsir
mbruvapdhhxltyckwtfdjonsie
mbruvapdghxlzyckwtfdjjnste
mbrdvzpdghxlcyckwtfqjonsie
mbruvapdghxlzyckwtnqbonsim
mbrovapdghxlzyckwtfpjousie
mymuvapdghxlzyjkwtfqjonsie
mbpuvapdghxlzyckwtfljcnsie
mbrxvapdghxlzyclwtfqjonpie
mbrueapdghxlzyckwtfqjopsia
mbruvapdghxlzycdwtfqjbfsie
tbruvavdghxlzyckwtmqjonsie
mbduvapdghxlzyckwrfqjrnsie
mkrsvapughxlzyckwtfqjonsie
mbruvapdghylzyckwtfqtolsie
mgruvapdglxldyckwtfqjonsie
mbrunapdghclzyckwtfqjonsiy
mbruvapdgrxlxyckwtfgjonsie
mbruvapdghxpzbckftfqjonsie
mbruvcpdghxyzyckotfqjonsie
mbruvapdghxlsyckwtfqcqnsie
mbruvapdghxlzzckwtfqjonskf
mbruvppdghxlzfckwtfqjgnsie
mbhuvapdghxlzytkwtfqjonoie
mbruvapdghxlzvrkwtfqjjnsie
mbmuvapdghxuzyckwtfqjonsze
mbruvapdghnlzycnwtfqjonsil
mbruvapdgholzyckitfqjonsia
mbruxapdghxlmyckwtfqbonsie
mbauvapdgholzyckwtfqjolsie
mbruvapdghxlzyckwtfqjotslq
dbrutapdghxlzyckwtfqjonsiv
mbruvapdzhxlyyckwtfbjonsie
mmruaapsghxlzyckwtfqjonsie
mbruvaldgqxqzyckwtfqjonsie
mbruvaodghxdzyjkwtfqjonsie
mbrcmatdghxlzyckwtfqjonsie
mbrqvapdgtxlzycewtfqjonsie
mjruvapdghzlzyckwtfqjonrie
mbruvapdghxopcckwtfqjonsie
mbruvapdghxszycwwtfqjoqsie
ybruvapdgixszyckwtfqjonsie
mbruvapxghslyyckwtfqjonsie
mbruvapdghslzyckwtkujonsie
rwruvapdghxlzyckwtfqjcnsie
obruvapdgtxlzyckwtfqionsie
lbruvapdghxqzyckwtfqjfnsie
mbrunapdghxlzyccatfqjonsie
mbruvapdghxlzyokltfqjdnsie
ybruvapdghxlzmckwtfqjmnsie
mbruwaadghxdzyckwtfqjonsie
muruvapdghxlzyckvtfqjonsim
mbruvapdghxlkyckwtxqjonjie
mbruvaqdghxlzyckwtfqjrnnie
mwruvapdghdlzyckttfqjonsie
mbruvapdgtelzyckwxfqjonsie
mbruvapdohxlzvckwtfqjonhie
mbrugapdgbxlzyckwtfqjynsie
mbruvapdghxlzyckwtlqjonjiu
mbruvapwghxlzyckwafqjonbie
wbruvapdghxlhyckwtfqjonsii
mbruvapdghxlzyckwtcqnonsiq
mbyuvapighxlzybkwtfqjonsie
mbrrvapdghxvzyckwtfqjonsio
mhruvapdghrlzyckwtfzjonsie
mtruvapvghxlzyckwtfnjonsie
mmrlhapdghxlzyckwtfqjonsie
mbruvapdgpxlzyjkwtfqjovsie
mbrucapdghxlzymkwtzqjonsie
mbeuvafdghxlzyckwtfqjonwie
mbruvapcghxlayckwtfqjonsii
mbruvabdghxlzyckwtfqyansie
mbruvjpdghxlzyckwtfqgfnsie
lbruvapdghxlzyckwtfqjonriv
mbrupapdghxlzycjwtfqronsie
mbpuvapdthxlzymkwtfqjonsie
mbiuvapdgixlzyckwxfqjonsie
mbruvapdghxyzyckwtfcjonsbe
mbrurapkghxlzyckwtfqjonzie
mbrufapdrhxlzyciwtfqjonsie
mbruvapdghxlzbckwtfqjoisae
ubruhapdghxlzuckwtfqjonsie
mbruvapdjhulzyckwtfqjonshe
mbruwapdgyxlzyckntfqjonsie
mwruvapdghplzyckwtfqjonsme
mbruvapjghtlzyckwtfqgonsie
pbruvapdghhlzyckwtfrjonsie
mbruvgpdihxqzyckwtfqjonsie
mbruvahdohxlzyckwtfijonsie
ibuuvapdghxlzyckwtfqjofsie
mbruvandghxlzyckwtfqjrnxie
mbrjvlpdghxlzyckwgfqjonsie
mbruvapogfxlzyckotfqjonsie
mbruvrpdghxlzyckutfejonsie
mbruvbpdghxlzyhkwtfqjonsip
mbruvapdghxlzyckmnfqjensie
mbruvapdghvlzyckwtfqjowsix
mbruvakdgholzwckwtfqjonsie
mbruvapdghxlzackwtfqconsae
mbruvapdghxlzyqvwtfqjlnsie
mprrvapdgfxlzyckwtfqjonsie
mbrunacdghxlhyckwtfqjonsie
obruvapdgsxlzyckwtfqjonvie
murcvapdghslzyckwtfqjonsie
mbruvapdghxlzyzkwmftjonsie
mbrwvapdgtvlzyckwtfqjonsie
mbxuvapdghxlzqcnwtfqjonsie
mbruvaddghxboyckwtfqjonsie
mhruvwndghxlzyckwtfqjonsie
mbrdvapdghxlzyckwmpqjonsie
mbruvapdgyxlzyckizfqjonsie
mbruvapdghxlzlckwtfqeowsie
mbruvbpdgrxlzyckwtfqjonsxe
mbruqapoghxlzyckwtvqjonsie
mbouhapdghmlzyckwtfqjonsie
mbruvapjghxidyckwtfqjonsie
mbsuvapkghxlkyckwtfqjonsie
mbruvlpdghxlzycrwtfqjonsis
mcrueapdghxlzyckwtfqjynsie
muruvapngbxlzyckwtfqjonsie
mbruvapdghxlzycawtfyjojsie
mbruvbpdghxczyjkwtfqjonsie
ybduvapdghxnzyckwtfqjonsie
mbruvbpdghxlzyckwtfbjousie
mbouvapdghxlzycbwtfqponsie
mbruvaedghplzycgwtfqjonsie
mbrhvapdghxlzyckytfqjgnsie
mbruvapdqbxleyckwtfqjonsie
mbruvapddhhldyckwtfqjonsie
mbruvapdghxlwrckwtfqjondie
mbruvapdmhxlzyckwtfqkonsve
xbbuvapdghxlzyckwtfkjonsie
mbruvapdghxlzyckwcfqjunkie
mbruvapdghxlzyckwtfqxonfib
mbrtvapkghxlzyckwtfqeonsie
mbruvazdghxldymkwtfqjonsie
kbruvapddhxlzfckwtfqjonsie
mbouvapdghxlpyckwtfqjoosie
mbauvapdghxlzyckwtfqjszsie
mbruvapdghtlzyckntfqtonsie
mbruvipdggxlzbckwtfqjonsie
mbruqapdghrlzyckwtfqjznsie
myruvacdghxlzyckwifqjonsie
mbruvapdghxlzuckwtfkjocsie
mwjuvapdghxlzyckwtfqjonsxe
mbruvapxghxlzickwtfqjobsie
mbrupapdghxtlyckwtfqjonsie
meruvapdjjxlzyckwtfqjonsie
mbruvkodghxlzyckwofqjonsie
mbruvapdgexlzyckwtgkjonsie
mbruvapwghxlzyckwtcqjonsiw
mbruvapdghxlzykkwtfqtoxsie
mbruvapdahxlzycgwtfwjonsie
mbruvapdgwxlhyckhtfqjonsie
mbruvapbghxlzycbhmfqjonsie
mbruvapdghxvzyzkwtfqjonsin
mbrcvapdqhxlzyckwyfqjonsie
zbruvaxdghxlzyckwgfqjonsie
mtruvapdghxlilckwtfqjonsie
bbruvapdghxlzyckwtfmjonsxe
mbruvajdghxlzyckwtfqfwnsie
mbruvapdgkxlzyckwtfqionpie
rbruvapdghxlryckwdfqjonsie
mbruvandghxlzyckwmfvjonsie
mbruvahdghxlzeckwtfqjonsme
mbruvnpcghxlzyckwtfqjobsie
mbruvapdghqlzyckwtfbjonsiy
mbruvavdghxlzyckwufqjodsie
mbruvapdghxlzyckwtfzmovsie
mbruvlpdghxuzyckwtfqjoesie
mbruvopdghxlzycwwtfqjansie
obruvapdghglzybkwtfqjonsie
mbpuvlpdghxlcyckwtfqjonsie
mbruvaidghxlzyckwtfmjonoie
mbruvapdihxzzyckwtfqjonsiy
mbquvapdghxlzyckwtfqconsme
mbruvapdghslzyckqtfqjojsie
mbrzdapdghxmzyckwtfqjonsie
mwruvapdghxozyckwtfqjonsxe
muruvapdgfxlzyckwtfqjojsie
wtruvapdghxlzyckvtfqjonsie
mbruvapdghxlzyckysfqjxnsie
mbruvrpdghxczyckktfqjonsie
mbquvapdghxlryckwtfqjonsne
mbruvapdghflzycvwtfqjpnsie
mbruvapughclzyckwtfqjonsin
mbrhvapdghxlpyckwtfqjonsre
mbruvapdgtxlzyckwtfqjoosit
mbrupapnghxhzyckwtfqjonsie
mmvuvapdvhxlzyckwtfqjonsie
mbruvaptghxlzyckwtfqjotsse
mgruvapvghxlzyckwtfqjonsix
mbrupapdghxszyckwtfqjunsie
mbruvkpdghelzyckwtfqjpnsie
mbruvrrdghjlzyckwtfqjonsie
mbruvapdghnlzyckwtfkjonsze
mbruvwpdghxlzyckwtfqhoysie
mbrsvapdfhxlzyckwtfqjobsie
mbruvapdgexezymkwtfqjonsie
ybruvapdghxlzyckwtfqxonsiw
mrruvapdghxdzyckwtfqjossie
mbruvapdghtlzyckwtfqconsiu
mbrpvapdghxlzlckwpfqjonsie
mbruvjpdghslzyckwtfqjjnsie
mhruvapoghxlzyckwtfvjonsie
mbrubqpdghvlzyckwtfqjonsie
mbruvapdghxlzackwtfqconsiw
mbruvapdgnxlzkckwtfqjdnsie
mbrudapgghelzyckwtfqjonsie
mbruvapdghxlzlakwbfqjonsie
mbpuvapdghxlzyckwtuqjonjie
abruvapdghxlzykkwtfqjonzie
mbrupupdghxlsyckwtfqjonsie
mbrsvupdghxlzyckwtfqjonkie
mxruvgpdghxllyckwtfqjonsie
mbrnvapdghxlzycbwtfqfonsie
mbrbxapdghxlzyckttfqjonsie
mbnuvapdghxlzyxkwtmqjonsie
mbrfvapdghjlzickwtfqjonsie
mbhuvupdghxlzyxkwtfqjonsie
mbrcvapdghxluyckwtfqjznsie
mbruvapdghxlzyckwofqjoxsiz
mbrevapdghxloyckwtfqjonnie
mbruvipdghnlzyckwtfqjopsie
mbxxvaptghxlzyckwtfqjonsie
mbruvcpdghxlztckwtjqjonsie
mqruvlpdghxlzyckotfqjonsie
mbruvapdgqxlzyckwtfqjpvsie
mbruvapdgvxlzyjkwtfqjbnsie
mbruvapdghxlgyckwtfqcocsie
mbruvapdghxkwyckwtfqjoqsie
mbrgvavdghxlzyckwxfqjonsie
qbruqapdgvxlzyckwtfqjonsie
mbauvapdghxlzgckwtfqjunsie
mbruvapdgdxluyckwtfqjoosie
mbruvapdghxlzykkwtfqwobsie
mbruvapdghxlzhcnwtfqjonqie
mbruvapdghxlzycbhmfqjonsie
mbruvapdghxluyczwtfqjontie
mbruvapnghxlzyckwnfqjonbie
moruvapdghxlzcckwtfqponsie
mbruvapfgxxlzyckwtfqjunsie
mbruvapdghxlryckvtfejonsie
mbrzvapdghxlzvcbwtfqjonsie
mbruvapdgqxlzyckwcfqjonsce
abruvupdrhxlzyckwtfqjonsie
mbrubaptghxlzyckwtfqjondie
mgruvapdgpxlzyckwtfijonsie
mbruvapdghxczlckwtfujonsie
mbruvapdgmmlzyckwtfqjonsir
mbruvapdhhxltyckwtfdjonsie
mbruvapdghxlzyckwtfdjjnste
mbrdvzpdghxlcyckwtfqjonsie
mbruvapdghxlzyckwtnqbonsim
mbrovapdghxlzyckwtfpjousie
mymuvapdghxlzyjkwtfqjonsie
mbpuvapdghxlzyckwtfljcnsie
mbrxvapdghxlzyclwtfqjonpie
mbrueapdghxlzyckwtfqjopsia
mbruvapdghxlzycdwtfqjbfsie
tbruvavdghxlzyckwtmqjonsie
mbduvapdghxlzyckwrfqjrnsie
mkrsvapughxlzyckwtfqjonsie
mbruvapdghylzyckwtfqtolsie
mgruvapdglxldyckwtfqjonsie
mbrunapdghclzyckwtfqjonsiy
mbruvapdgrxlxyckwtfgjonsie
mbruvapdghxpzbckftfqjonsie
mbruvcpdghxyzyckotfqjonsie
mbruvapdghxlsyckwtfqcqnsie
mbruvapdghxlzzckwtfqjonskf
mbruvppdghxlzfckwtfqjgnsie
mbhuvapdghxlzytkwtfqjonoie
mbruvapdghxlzvrkwtfqjjnsie
mbmuvapdghxuzyckwtfqjonsze
mbruvapdghnlzycnwtfqjonsil
mbruvapdgholzyckitfqjonsia
mbruxapdghxlmyckwtfqbonsie
mbauvapdgholzyckwtfqjolsie
mbruvapdghxlzyckwtfqjotslq
dbrutapdghxlzyckwtfqjonsiv
mbruvapdzhxlyyckwtfbjonsie
mmruaapsghxlzyckwtfqjonsie
mbruvaldgqxqzyckwtfqjonsie
mbruvaodghxdzyjkwtfqjonsie
mbrcmatdghxlzyckwtfqjonsie
mbrqvapdgtxlzycewtfqjonsie
mjruvapdghzlzyckwtfqjonrie
mbruvapdghxopcckwtfqjonsie
mbruvapdghxszycwwtfqjoqsie
mbruvapdgoxezyckwtjqjonsie

View File

@@ -1,36 +1,36 @@
#include <string>
#include <iostream>
#include <fstream>
bool isRepeat(std::string line, int repeats) {
for (char c = 'a'; c <= 'z'; ++c) {
int count = 0;
for (size_t i = 0; i < line.size(); ++i) {
if (line[i] == c)
++count;
}
if (count == repeats)
return true;
}
return false;
}
int checkSum(std::string fileName) {
std::fstream input(fileName);
std::string line;
int doubles = 0;
int triples = 0;
while (!input.eof()) {
std::getline(input, line);
if (isRepeat(line, 2))
++doubles;
if (isRepeat(line, 3))
++triples;
}
return doubles * triples;
}
int main(int argc, char** argv) {
std::cout << "Found: " << checkSum("input.txt") << std::endl;
}
#include <string>
#include <iostream>
#include <fstream>
bool isRepeat(std::string line, int repeats) {
for (char c = 'a'; c <= 'z'; ++c) {
int count = 0;
for (size_t i = 0; i < line.size(); ++i) {
if (line[i] == c)
++count;
}
if (count == repeats)
return true;
}
return false;
}
int checkSum(std::string fileName) {
std::fstream input(fileName);
std::string line;
int doubles = 0;
int triples = 0;
while (!input.eof()) {
std::getline(input, line);
if (isRepeat(line, 2))
++doubles;
if (isRepeat(line, 3))
++triples;
}
return doubles * triples;
}
int main(int argc, char** argv) {
std::cout << "Found: " << checkSum("input.txt") << std::endl;
}

View File

@@ -1,15 +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.
--- 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.)

View File

@@ -1,250 +1,250 @@
ybruvapdgixszyckwtfqjonsie
mbruvapxghslyyckwtfqjonsie
mbruvapdghslzyckwtkujonsie
rwruvapdghxlzyckwtfqjcnsie
obruvapdgtxlzyckwtfqionsie
lbruvapdghxqzyckwtfqjfnsie
mbrunapdghxlzyccatfqjonsie
mbruvapdghxlzyokltfqjdnsie
ybruvapdghxlzmckwtfqjmnsie
mbruwaadghxdzyckwtfqjonsie
muruvapdghxlzyckvtfqjonsim
mbruvapdghxlkyckwtxqjonjie
mbruvaqdghxlzyckwtfqjrnnie
mwruvapdghdlzyckttfqjonsie
mbruvapdgtelzyckwxfqjonsie
mbruvapdohxlzvckwtfqjonhie
mbrugapdgbxlzyckwtfqjynsie
mbruvapdghxlzyckwtlqjonjiu
mbruvapwghxlzyckwafqjonbie
wbruvapdghxlhyckwtfqjonsii
mbruvapdghxlzyckwtcqnonsiq
mbyuvapighxlzybkwtfqjonsie
mbrrvapdghxvzyckwtfqjonsio
mhruvapdghrlzyckwtfzjonsie
mtruvapvghxlzyckwtfnjonsie
mmrlhapdghxlzyckwtfqjonsie
mbruvapdgpxlzyjkwtfqjovsie
mbrucapdghxlzymkwtzqjonsie
mbeuvafdghxlzyckwtfqjonwie
mbruvapcghxlayckwtfqjonsii
mbruvabdghxlzyckwtfqyansie
mbruvjpdghxlzyckwtfqgfnsie
lbruvapdghxlzyckwtfqjonriv
mbrupapdghxlzycjwtfqronsie
mbpuvapdthxlzymkwtfqjonsie
mbiuvapdgixlzyckwxfqjonsie
mbruvapdghxyzyckwtfcjonsbe
mbrurapkghxlzyckwtfqjonzie
mbrufapdrhxlzyciwtfqjonsie
mbruvapdghxlzbckwtfqjoisae
ubruhapdghxlzuckwtfqjonsie
mbruvapdjhulzyckwtfqjonshe
mbruwapdgyxlzyckntfqjonsie
mwruvapdghplzyckwtfqjonsme
mbruvapjghtlzyckwtfqgonsie
pbruvapdghhlzyckwtfrjonsie
mbruvgpdihxqzyckwtfqjonsie
mbruvahdohxlzyckwtfijonsie
ibuuvapdghxlzyckwtfqjofsie
mbruvandghxlzyckwtfqjrnxie
mbrjvlpdghxlzyckwgfqjonsie
mbruvapogfxlzyckotfqjonsie
mbruvrpdghxlzyckutfejonsie
mbruvbpdghxlzyhkwtfqjonsip
mbruvapdghxlzyckmnfqjensie
mbruvapdghvlzyckwtfqjowsix
mbruvakdgholzwckwtfqjonsie
mbruvapdghxlzackwtfqconsae
mbruvapdghxlzyqvwtfqjlnsie
mprrvapdgfxlzyckwtfqjonsie
mbrunacdghxlhyckwtfqjonsie
obruvapdgsxlzyckwtfqjonvie
murcvapdghslzyckwtfqjonsie
mbruvapdghxlzyzkwmftjonsie
mbrwvapdgtvlzyckwtfqjonsie
mbxuvapdghxlzqcnwtfqjonsie
mbruvaddghxboyckwtfqjonsie
mhruvwndghxlzyckwtfqjonsie
mbrdvapdghxlzyckwmpqjonsie
mbruvapdgyxlzyckizfqjonsie
mbruvapdghxlzlckwtfqeowsie
mbruvbpdgrxlzyckwtfqjonsxe
mbruqapoghxlzyckwtvqjonsie
mbouhapdghmlzyckwtfqjonsie
mbruvapjghxidyckwtfqjonsie
mbsuvapkghxlkyckwtfqjonsie
mbruvlpdghxlzycrwtfqjonsis
mcrueapdghxlzyckwtfqjynsie
muruvapngbxlzyckwtfqjonsie
mbruvapdghxlzycawtfyjojsie
mbruvbpdghxczyjkwtfqjonsie
ybduvapdghxnzyckwtfqjonsie
mbruvbpdghxlzyckwtfbjousie
mbouvapdghxlzycbwtfqponsie
mbruvaedghplzycgwtfqjonsie
mbrhvapdghxlzyckytfqjgnsie
mbruvapdqbxleyckwtfqjonsie
mbruvapddhhldyckwtfqjonsie
mbruvapdghxlwrckwtfqjondie
mbruvapdmhxlzyckwtfqkonsve
xbbuvapdghxlzyckwtfkjonsie
mbruvapdghxlzyckwcfqjunkie
mbruvapdghxlzyckwtfqxonfib
mbrtvapkghxlzyckwtfqeonsie
mbruvazdghxldymkwtfqjonsie
kbruvapddhxlzfckwtfqjonsie
mbouvapdghxlpyckwtfqjoosie
mbauvapdghxlzyckwtfqjszsie
mbruvapdghtlzyckntfqtonsie
mbruvipdggxlzbckwtfqjonsie
mbruqapdghrlzyckwtfqjznsie
myruvacdghxlzyckwifqjonsie
mbruvapdghxlzuckwtfkjocsie
mwjuvapdghxlzyckwtfqjonsxe
mbruvapxghxlzickwtfqjobsie
mbrupapdghxtlyckwtfqjonsie
meruvapdjjxlzyckwtfqjonsie
mbruvkodghxlzyckwofqjonsie
mbruvapdgexlzyckwtgkjonsie
mbruvapwghxlzyckwtcqjonsiw
mbruvapdghxlzykkwtfqtoxsie
mbruvapdahxlzycgwtfwjonsie
mbruvapdgwxlhyckhtfqjonsie
mbruvapbghxlzycbhmfqjonsie
mbruvapdghxvzyzkwtfqjonsin
mbrcvapdqhxlzyckwyfqjonsie
zbruvaxdghxlzyckwgfqjonsie
mtruvapdghxlilckwtfqjonsie
bbruvapdghxlzyckwtfmjonsxe
mbruvajdghxlzyckwtfqfwnsie
mbruvapdgkxlzyckwtfqionpie
rbruvapdghxlryckwdfqjonsie
mbruvandghxlzyckwmfvjonsie
mbruvahdghxlzeckwtfqjonsme
mbruvnpcghxlzyckwtfqjobsie
mbruvapdghqlzyckwtfbjonsiy
mbruvavdghxlzyckwufqjodsie
mbruvapdghxlzyckwtfzmovsie
mbruvlpdghxuzyckwtfqjoesie
mbruvopdghxlzycwwtfqjansie
obruvapdghglzybkwtfqjonsie
mbpuvlpdghxlcyckwtfqjonsie
mbruvaidghxlzyckwtfmjonoie
mbruvapdihxzzyckwtfqjonsiy
mbquvapdghxlzyckwtfqconsme
mbruvapdghslzyckqtfqjojsie
mbrzdapdghxmzyckwtfqjonsie
mwruvapdghxozyckwtfqjonsxe
muruvapdgfxlzyckwtfqjojsie
wtruvapdghxlzyckvtfqjonsie
mbruvapdghxlzyckysfqjxnsie
mbruvrpdghxczyckktfqjonsie
mbquvapdghxlryckwtfqjonsne
mbruvapdghflzycvwtfqjpnsie
mbruvapughclzyckwtfqjonsin
mbrhvapdghxlpyckwtfqjonsre
mbruvapdgtxlzyckwtfqjoosit
mbrupapnghxhzyckwtfqjonsie
mmvuvapdvhxlzyckwtfqjonsie
mbruvaptghxlzyckwtfqjotsse
mgruvapvghxlzyckwtfqjonsix
mbrupapdghxszyckwtfqjunsie
mbruvkpdghelzyckwtfqjpnsie
mbruvrrdghjlzyckwtfqjonsie
mbruvapdghnlzyckwtfkjonsze
mbruvwpdghxlzyckwtfqhoysie
mbrsvapdfhxlzyckwtfqjobsie
mbruvapdgexezymkwtfqjonsie
ybruvapdghxlzyckwtfqxonsiw
mrruvapdghxdzyckwtfqjossie
mbruvapdghtlzyckwtfqconsiu
mbrpvapdghxlzlckwpfqjonsie
mbruvjpdghslzyckwtfqjjnsie
mhruvapoghxlzyckwtfvjonsie
mbrubqpdghvlzyckwtfqjonsie
mbruvapdghxlzackwtfqconsiw
mbruvapdgnxlzkckwtfqjdnsie
mbrudapgghelzyckwtfqjonsie
mbruvapdghxlzlakwbfqjonsie
mbpuvapdghxlzyckwtuqjonjie
abruvapdghxlzykkwtfqjonzie
mbrupupdghxlsyckwtfqjonsie
mbrsvupdghxlzyckwtfqjonkie
mxruvgpdghxllyckwtfqjonsie
mbrnvapdghxlzycbwtfqfonsie
mbrbxapdghxlzyckttfqjonsie
mbnuvapdghxlzyxkwtmqjonsie
mbrfvapdghjlzickwtfqjonsie
mbhuvupdghxlzyxkwtfqjonsie
mbrcvapdghxluyckwtfqjznsie
mbruvapdghxlzyckwofqjoxsiz
mbrevapdghxloyckwtfqjonnie
mbruvipdghnlzyckwtfqjopsie
mbxxvaptghxlzyckwtfqjonsie
mbruvcpdghxlztckwtjqjonsie
mqruvlpdghxlzyckotfqjonsie
mbruvapdgqxlzyckwtfqjpvsie
mbruvapdgvxlzyjkwtfqjbnsie
mbruvapdghxlgyckwtfqcocsie
mbruvapdghxkwyckwtfqjoqsie
mbrgvavdghxlzyckwxfqjonsie
qbruqapdgvxlzyckwtfqjonsie
mbauvapdghxlzgckwtfqjunsie
mbruvapdgdxluyckwtfqjoosie
mbruvapdghxlzykkwtfqwobsie
mbruvapdghxlzhcnwtfqjonqie
mbruvapdghxlzycbhmfqjonsie
mbruvapdghxluyczwtfqjontie
mbruvapnghxlzyckwnfqjonbie
moruvapdghxlzcckwtfqponsie
mbruvapfgxxlzyckwtfqjunsie
mbruvapdghxlryckvtfejonsie
mbrzvapdghxlzvcbwtfqjonsie
mbruvapdgqxlzyckwcfqjonsce
abruvupdrhxlzyckwtfqjonsie
mbrubaptghxlzyckwtfqjondie
mgruvapdgpxlzyckwtfijonsie
mbruvapdghxczlckwtfujonsie
mbruvapdgmmlzyckwtfqjonsir
mbruvapdhhxltyckwtfdjonsie
mbruvapdghxlzyckwtfdjjnste
mbrdvzpdghxlcyckwtfqjonsie
mbruvapdghxlzyckwtnqbonsim
mbrovapdghxlzyckwtfpjousie
mymuvapdghxlzyjkwtfqjonsie
mbpuvapdghxlzyckwtfljcnsie
mbrxvapdghxlzyclwtfqjonpie
mbrueapdghxlzyckwtfqjopsia
mbruvapdghxlzycdwtfqjbfsie
tbruvavdghxlzyckwtmqjonsie
mbduvapdghxlzyckwrfqjrnsie
mkrsvapughxlzyckwtfqjonsie
mbruvapdghylzyckwtfqtolsie
mgruvapdglxldyckwtfqjonsie
mbrunapdghclzyckwtfqjonsiy
mbruvapdgrxlxyckwtfgjonsie
mbruvapdghxpzbckftfqjonsie
mbruvcpdghxyzyckotfqjonsie
mbruvapdghxlsyckwtfqcqnsie
mbruvapdghxlzzckwtfqjonskf
mbruvppdghxlzfckwtfqjgnsie
mbhuvapdghxlzytkwtfqjonoie
mbruvapdghxlzvrkwtfqjjnsie
mbmuvapdghxuzyckwtfqjonsze
mbruvapdghnlzycnwtfqjonsil
mbruvapdgholzyckitfqjonsia
mbruxapdghxlmyckwtfqbonsie
mbauvapdgholzyckwtfqjolsie
mbruvapdghxlzyckwtfqjotslq
dbrutapdghxlzyckwtfqjonsiv
mbruvapdzhxlyyckwtfbjonsie
mmruaapsghxlzyckwtfqjonsie
mbruvaldgqxqzyckwtfqjonsie
mbruvaodghxdzyjkwtfqjonsie
mbrcmatdghxlzyckwtfqjonsie
mbrqvapdgtxlzycewtfqjonsie
mjruvapdghzlzyckwtfqjonrie
mbruvapdghxopcckwtfqjonsie
mbruvapdghxszycwwtfqjoqsie
ybruvapdgixszyckwtfqjonsie
mbruvapxghslyyckwtfqjonsie
mbruvapdghslzyckwtkujonsie
rwruvapdghxlzyckwtfqjcnsie
obruvapdgtxlzyckwtfqionsie
lbruvapdghxqzyckwtfqjfnsie
mbrunapdghxlzyccatfqjonsie
mbruvapdghxlzyokltfqjdnsie
ybruvapdghxlzmckwtfqjmnsie
mbruwaadghxdzyckwtfqjonsie
muruvapdghxlzyckvtfqjonsim
mbruvapdghxlkyckwtxqjonjie
mbruvaqdghxlzyckwtfqjrnnie
mwruvapdghdlzyckttfqjonsie
mbruvapdgtelzyckwxfqjonsie
mbruvapdohxlzvckwtfqjonhie
mbrugapdgbxlzyckwtfqjynsie
mbruvapdghxlzyckwtlqjonjiu
mbruvapwghxlzyckwafqjonbie
wbruvapdghxlhyckwtfqjonsii
mbruvapdghxlzyckwtcqnonsiq
mbyuvapighxlzybkwtfqjonsie
mbrrvapdghxvzyckwtfqjonsio
mhruvapdghrlzyckwtfzjonsie
mtruvapvghxlzyckwtfnjonsie
mmrlhapdghxlzyckwtfqjonsie
mbruvapdgpxlzyjkwtfqjovsie
mbrucapdghxlzymkwtzqjonsie
mbeuvafdghxlzyckwtfqjonwie
mbruvapcghxlayckwtfqjonsii
mbruvabdghxlzyckwtfqyansie
mbruvjpdghxlzyckwtfqgfnsie
lbruvapdghxlzyckwtfqjonriv
mbrupapdghxlzycjwtfqronsie
mbpuvapdthxlzymkwtfqjonsie
mbiuvapdgixlzyckwxfqjonsie
mbruvapdghxyzyckwtfcjonsbe
mbrurapkghxlzyckwtfqjonzie
mbrufapdrhxlzyciwtfqjonsie
mbruvapdghxlzbckwtfqjoisae
ubruhapdghxlzuckwtfqjonsie
mbruvapdjhulzyckwtfqjonshe
mbruwapdgyxlzyckntfqjonsie
mwruvapdghplzyckwtfqjonsme
mbruvapjghtlzyckwtfqgonsie
pbruvapdghhlzyckwtfrjonsie
mbruvgpdihxqzyckwtfqjonsie
mbruvahdohxlzyckwtfijonsie
ibuuvapdghxlzyckwtfqjofsie
mbruvandghxlzyckwtfqjrnxie
mbrjvlpdghxlzyckwgfqjonsie
mbruvapogfxlzyckotfqjonsie
mbruvrpdghxlzyckutfejonsie
mbruvbpdghxlzyhkwtfqjonsip
mbruvapdghxlzyckmnfqjensie
mbruvapdghvlzyckwtfqjowsix
mbruvakdgholzwckwtfqjonsie
mbruvapdghxlzackwtfqconsae
mbruvapdghxlzyqvwtfqjlnsie
mprrvapdgfxlzyckwtfqjonsie
mbrunacdghxlhyckwtfqjonsie
obruvapdgsxlzyckwtfqjonvie
murcvapdghslzyckwtfqjonsie
mbruvapdghxlzyzkwmftjonsie
mbrwvapdgtvlzyckwtfqjonsie
mbxuvapdghxlzqcnwtfqjonsie
mbruvaddghxboyckwtfqjonsie
mhruvwndghxlzyckwtfqjonsie
mbrdvapdghxlzyckwmpqjonsie
mbruvapdgyxlzyckizfqjonsie
mbruvapdghxlzlckwtfqeowsie
mbruvbpdgrxlzyckwtfqjonsxe
mbruqapoghxlzyckwtvqjonsie
mbouhapdghmlzyckwtfqjonsie
mbruvapjghxidyckwtfqjonsie
mbsuvapkghxlkyckwtfqjonsie
mbruvlpdghxlzycrwtfqjonsis
mcrueapdghxlzyckwtfqjynsie
muruvapngbxlzyckwtfqjonsie
mbruvapdghxlzycawtfyjojsie
mbruvbpdghxczyjkwtfqjonsie
ybduvapdghxnzyckwtfqjonsie
mbruvbpdghxlzyckwtfbjousie
mbouvapdghxlzycbwtfqponsie
mbruvaedghplzycgwtfqjonsie
mbrhvapdghxlzyckytfqjgnsie
mbruvapdqbxleyckwtfqjonsie
mbruvapddhhldyckwtfqjonsie
mbruvapdghxlwrckwtfqjondie
mbruvapdmhxlzyckwtfqkonsve
xbbuvapdghxlzyckwtfkjonsie
mbruvapdghxlzyckwcfqjunkie
mbruvapdghxlzyckwtfqxonfib
mbrtvapkghxlzyckwtfqeonsie
mbruvazdghxldymkwtfqjonsie
kbruvapddhxlzfckwtfqjonsie
mbouvapdghxlpyckwtfqjoosie
mbauvapdghxlzyckwtfqjszsie
mbruvapdghtlzyckntfqtonsie
mbruvipdggxlzbckwtfqjonsie
mbruqapdghrlzyckwtfqjznsie
myruvacdghxlzyckwifqjonsie
mbruvapdghxlzuckwtfkjocsie
mwjuvapdghxlzyckwtfqjonsxe
mbruvapxghxlzickwtfqjobsie
mbrupapdghxtlyckwtfqjonsie
meruvapdjjxlzyckwtfqjonsie
mbruvkodghxlzyckwofqjonsie
mbruvapdgexlzyckwtgkjonsie
mbruvapwghxlzyckwtcqjonsiw
mbruvapdghxlzykkwtfqtoxsie
mbruvapdahxlzycgwtfwjonsie
mbruvapdgwxlhyckhtfqjonsie
mbruvapbghxlzycbhmfqjonsie
mbruvapdghxvzyzkwtfqjonsin
mbrcvapdqhxlzyckwyfqjonsie
zbruvaxdghxlzyckwgfqjonsie
mtruvapdghxlilckwtfqjonsie
bbruvapdghxlzyckwtfmjonsxe
mbruvajdghxlzyckwtfqfwnsie
mbruvapdgkxlzyckwtfqionpie
rbruvapdghxlryckwdfqjonsie
mbruvandghxlzyckwmfvjonsie
mbruvahdghxlzeckwtfqjonsme
mbruvnpcghxlzyckwtfqjobsie
mbruvapdghqlzyckwtfbjonsiy
mbruvavdghxlzyckwufqjodsie
mbruvapdghxlzyckwtfzmovsie
mbruvlpdghxuzyckwtfqjoesie
mbruvopdghxlzycwwtfqjansie
obruvapdghglzybkwtfqjonsie
mbpuvlpdghxlcyckwtfqjonsie
mbruvaidghxlzyckwtfmjonoie
mbruvapdihxzzyckwtfqjonsiy
mbquvapdghxlzyckwtfqconsme
mbruvapdghslzyckqtfqjojsie
mbrzdapdghxmzyckwtfqjonsie
mwruvapdghxozyckwtfqjonsxe
muruvapdgfxlzyckwtfqjojsie
wtruvapdghxlzyckvtfqjonsie
mbruvapdghxlzyckysfqjxnsie
mbruvrpdghxczyckktfqjonsie
mbquvapdghxlryckwtfqjonsne
mbruvapdghflzycvwtfqjpnsie
mbruvapughclzyckwtfqjonsin
mbrhvapdghxlpyckwtfqjonsre
mbruvapdgtxlzyckwtfqjoosit
mbrupapnghxhzyckwtfqjonsie
mmvuvapdvhxlzyckwtfqjonsie
mbruvaptghxlzyckwtfqjotsse
mgruvapvghxlzyckwtfqjonsix
mbrupapdghxszyckwtfqjunsie
mbruvkpdghelzyckwtfqjpnsie
mbruvrrdghjlzyckwtfqjonsie
mbruvapdghnlzyckwtfkjonsze
mbruvwpdghxlzyckwtfqhoysie
mbrsvapdfhxlzyckwtfqjobsie
mbruvapdgexezymkwtfqjonsie
ybruvapdghxlzyckwtfqxonsiw
mrruvapdghxdzyckwtfqjossie
mbruvapdghtlzyckwtfqconsiu
mbrpvapdghxlzlckwpfqjonsie
mbruvjpdghslzyckwtfqjjnsie
mhruvapoghxlzyckwtfvjonsie
mbrubqpdghvlzyckwtfqjonsie
mbruvapdghxlzackwtfqconsiw
mbruvapdgnxlzkckwtfqjdnsie
mbrudapgghelzyckwtfqjonsie
mbruvapdghxlzlakwbfqjonsie
mbpuvapdghxlzyckwtuqjonjie
abruvapdghxlzykkwtfqjonzie
mbrupupdghxlsyckwtfqjonsie
mbrsvupdghxlzyckwtfqjonkie
mxruvgpdghxllyckwtfqjonsie
mbrnvapdghxlzycbwtfqfonsie
mbrbxapdghxlzyckttfqjonsie
mbnuvapdghxlzyxkwtmqjonsie
mbrfvapdghjlzickwtfqjonsie
mbhuvupdghxlzyxkwtfqjonsie
mbrcvapdghxluyckwtfqjznsie
mbruvapdghxlzyckwofqjoxsiz
mbrevapdghxloyckwtfqjonnie
mbruvipdghnlzyckwtfqjopsie
mbxxvaptghxlzyckwtfqjonsie
mbruvcpdghxlztckwtjqjonsie
mqruvlpdghxlzyckotfqjonsie
mbruvapdgqxlzyckwtfqjpvsie
mbruvapdgvxlzyjkwtfqjbnsie
mbruvapdghxlgyckwtfqcocsie
mbruvapdghxkwyckwtfqjoqsie
mbrgvavdghxlzyckwxfqjonsie
qbruqapdgvxlzyckwtfqjonsie
mbauvapdghxlzgckwtfqjunsie
mbruvapdgdxluyckwtfqjoosie
mbruvapdghxlzykkwtfqwobsie
mbruvapdghxlzhcnwtfqjonqie
mbruvapdghxlzycbhmfqjonsie
mbruvapdghxluyczwtfqjontie
mbruvapnghxlzyckwnfqjonbie
moruvapdghxlzcckwtfqponsie
mbruvapfgxxlzyckwtfqjunsie
mbruvapdghxlryckvtfejonsie
mbrzvapdghxlzvcbwtfqjonsie
mbruvapdgqxlzyckwcfqjonsce
abruvupdrhxlzyckwtfqjonsie
mbrubaptghxlzyckwtfqjondie
mgruvapdgpxlzyckwtfijonsie
mbruvapdghxczlckwtfujonsie
mbruvapdgmmlzyckwtfqjonsir
mbruvapdhhxltyckwtfdjonsie
mbruvapdghxlzyckwtfdjjnste
mbrdvzpdghxlcyckwtfqjonsie
mbruvapdghxlzyckwtnqbonsim
mbrovapdghxlzyckwtfpjousie
mymuvapdghxlzyjkwtfqjonsie
mbpuvapdghxlzyckwtfljcnsie
mbrxvapdghxlzyclwtfqjonpie
mbrueapdghxlzyckwtfqjopsia
mbruvapdghxlzycdwtfqjbfsie
tbruvavdghxlzyckwtmqjonsie
mbduvapdghxlzyckwrfqjrnsie
mkrsvapughxlzyckwtfqjonsie
mbruvapdghylzyckwtfqtolsie
mgruvapdglxldyckwtfqjonsie
mbrunapdghclzyckwtfqjonsiy
mbruvapdgrxlxyckwtfgjonsie
mbruvapdghxpzbckftfqjonsie
mbruvcpdghxyzyckotfqjonsie
mbruvapdghxlsyckwtfqcqnsie
mbruvapdghxlzzckwtfqjonskf
mbruvppdghxlzfckwtfqjgnsie
mbhuvapdghxlzytkwtfqjonoie
mbruvapdghxlzvrkwtfqjjnsie
mbmuvapdghxuzyckwtfqjonsze
mbruvapdghnlzycnwtfqjonsil
mbruvapdgholzyckitfqjonsia
mbruxapdghxlmyckwtfqbonsie
mbauvapdgholzyckwtfqjolsie
mbruvapdghxlzyckwtfqjotslq
dbrutapdghxlzyckwtfqjonsiv
mbruvapdzhxlyyckwtfbjonsie
mmruaapsghxlzyckwtfqjonsie
mbruvaldgqxqzyckwtfqjonsie
mbruvaodghxdzyjkwtfqjonsie
mbrcmatdghxlzyckwtfqjonsie
mbrqvapdgtxlzycewtfqjonsie
mjruvapdghzlzyckwtfqjonrie
mbruvapdghxopcckwtfqjonsie
mbruvapdghxszycwwtfqjoqsie
mbruvapdgoxezyckwtjqjonsie

View File

@@ -1,50 +1,50 @@
#include <string>
#include <fstream>
#include <iostream>
#include <vector>
std::string equalLetters(std::string fileName) {
std::fstream input(fileName);
std::string line;
std::string a;
std::string b;
std::string answer;
std::vector<std::string> lines;
while (!input.eof()) {
std::getline(input, line);
lines.push_back(line);
}
for (size_t i = 0; i < lines.size(); ++i) {
int count = 0;
a = lines[i];
for (size_t j = i + 1; j < lines.size(); ++j) {
b = lines[j];
count = 0;
for (size_t k = 0; k < a.size(); ++k) {
if (a[k] != b[k])
++count;
if (count > 1)
break;
}
if (count == 1)
break;
}
if (count == 1)
break;
}
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] == b[i])
answer += a[i];
}
return answer;
}
int main(int argc, char** argv) {
std::cout << "Found: " << equalLetters("input.txt") << std::endl;
}
#include <string>
#include <fstream>
#include <iostream>
#include <vector>
std::string equalLetters(std::string fileName) {
std::fstream input(fileName);
std::string line;
std::string a;
std::string b;
std::string answer;
std::vector<std::string> lines;
while (!input.eof()) {
std::getline(input, line);
lines.push_back(line);
}
for (size_t i = 0; i < lines.size(); ++i) {
int count = 0;
a = lines[i];
for (size_t j = i + 1; j < lines.size(); ++j) {
b = lines[j];
count = 0;
for (size_t k = 0; k < a.size(); ++k) {
if (a[k] != b[k])
++count;
if (count > 1)
break;
}
if (count == 1)
break;
}
if (count == 1)
break;
}
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] == b[i])
answer += a[i];
}
return answer;
}
int main(int argc, char** argv) {
std::cout << "Found: " << equalLetters("input.txt") << std::endl;
}

View File

@@ -1,107 +1,107 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace challenge1 {
class Program {
static string[] Lines {get; set;}
static List<Claim> Claims {get; set;}
static void Main(string[] args) {
Claims = new List<Claim>();
Console.WriteLine("Reading input.txt");
Lines = File.ReadAllLines("./input.txt");
foreach (string line in Lines) {
Claim current = new Claim(line);
Claims.Add(current);
current.Print();
}
Fabric fabric = new Fabric(Claims);
Console.WriteLine("Found: " + fabric.CalculateOverlaps() + " overlaps");
}
public static void printArray(string[] arr) {
foreach (string str in arr) {
Console.WriteLine(str);
}
}
}
class Claim {
public int ID {get; set;}
public int X {get; set;}
public int Y {get; set;}
public int W {get; set;}
public int H {get; set;}
public string Source {get; set;}
public Claim(string source) {
this.Source = source;
ParseSource();
}
private void ParseSource() {
Console.WriteLine("Parsing: " + this.Source);
string[] source = this.Source.Split('#');
string[] idAndRest = source[1].Split('@');
this.ID = int.Parse(idAndRest[0]);
string[] fromSides = idAndRest[1].Split(',');
string[] afterColon = fromSides[1].Split(':');
this.X = int.Parse(fromSides[0]);
this.Y = int.Parse(afterColon[0]);
string[] dimensions = afterColon[1].Split('x');
this.W = int.Parse(dimensions[0]);
this.H = int.Parse(dimensions[1]);
}
public void Print() {
Console.WriteLine("Claim ID: " + this.ID);
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
Console.WriteLine("Parsed from source: " + this.Source);
Console.WriteLine();
}
}
class Fabric {
public List<Claim> Claims;
private int[,] Board;
public Fabric(List<Claim> claims) {
this.Claims = claims;
this.Board = new int[10000, 10000];
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
Board[i, j] = 0;
}
}
}
public int CalculateOverlaps() {
int overlaps = 0;
int i = 0;
foreach (Claim claim in this.Claims) {
Console.WriteLine("Processing claim ID: " + claim.ID);
for (int x = claim.X; x < claim.X + claim.W; x++) {
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
Board[x, y]++;
}
}
i++;
}
for (i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
if (Board[i,j] > 1) overlaps++;
}
}
return overlaps;
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace challenge1 {
class Program {
static string[] Lines {get; set;}
static List<Claim> Claims {get; set;}
static void Main(string[] args) {
Claims = new List<Claim>();
Console.WriteLine("Reading input.txt");
Lines = File.ReadAllLines("./input.txt");
foreach (string line in Lines) {
Claim current = new Claim(line);
Claims.Add(current);
current.Print();
}
Fabric fabric = new Fabric(Claims);
Console.WriteLine("Found: " + fabric.CalculateOverlaps() + " overlaps");
}
public static void printArray(string[] arr) {
foreach (string str in arr) {
Console.WriteLine(str);
}
}
}
class Claim {
public int ID {get; set;}
public int X {get; set;}
public int Y {get; set;}
public int W {get; set;}
public int H {get; set;}
public string Source {get; set;}
public Claim(string source) {
this.Source = source;
ParseSource();
}
private void ParseSource() {
Console.WriteLine("Parsing: " + this.Source);
string[] source = this.Source.Split('#');
string[] idAndRest = source[1].Split('@');
this.ID = int.Parse(idAndRest[0]);
string[] fromSides = idAndRest[1].Split(',');
string[] afterColon = fromSides[1].Split(':');
this.X = int.Parse(fromSides[0]);
this.Y = int.Parse(afterColon[0]);
string[] dimensions = afterColon[1].Split('x');
this.W = int.Parse(dimensions[0]);
this.H = int.Parse(dimensions[1]);
}
public void Print() {
Console.WriteLine("Claim ID: " + this.ID);
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
Console.WriteLine("Parsed from source: " + this.Source);
Console.WriteLine();
}
}
class Fabric {
public List<Claim> Claims;
private int[,] Board;
public Fabric(List<Claim> claims) {
this.Claims = claims;
this.Board = new int[10000, 10000];
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
Board[i, j] = 0;
}
}
}
public int CalculateOverlaps() {
int overlaps = 0;
int i = 0;
foreach (Claim claim in this.Claims) {
Console.WriteLine("Processing claim ID: " + claim.ID);
for (int x = claim.X; x < claim.X + claim.W; x++) {
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
Board[x, y]++;
}
}
i++;
}
for (i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
if (Board[i,j] > 1) overlaps++;
}
}
return overlaps;
}
}
}

View File

@@ -1,40 +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.)
--- 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?

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@@ -1,115 +1,115 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace challenge2 {
class Program {
static string[] Lines {get; set;}
static List<Claim> Claims {get; set;}
static void Main(string[] args) {
Claims = new List<Claim>();
Console.WriteLine("Reading input.txt");
Lines = File.ReadAllLines("./input.txt");
foreach (string line in Lines) {
Claim current = new Claim(line);
Claims.Add(current);
current.Print();
}
Fabric fabric = new Fabric(Claims);
Console.WriteLine("Found ID: " + fabric.CalculateOverlaps());
}
public static void printArray(string[] arr) {
foreach (string str in arr) {
Console.WriteLine(str);
}
}
}
class Claim {
public int ID {get; set;}
public int X {get; set;}
public int Y {get; set;}
public int W {get; set;}
public int H {get; set;}
public string Source {get; set;}
public Claim(string source) {
this.Source = source;
ParseSource();
}
private void ParseSource() {
Console.WriteLine("Parsing: " + this.Source);
string[] source = this.Source.Split('#');
string[] idAndRest = source[1].Split('@');
this.ID = int.Parse(idAndRest[0]);
string[] fromSides = idAndRest[1].Split(',');
string[] afterColon = fromSides[1].Split(':');
this.X = int.Parse(fromSides[0]);
this.Y = int.Parse(afterColon[0]);
string[] dimensions = afterColon[1].Split('x');
this.W = int.Parse(dimensions[0]);
this.H = int.Parse(dimensions[1]);
}
public void Print() {
Console.WriteLine("Claim ID: " + this.ID);
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
Console.WriteLine("Parsed from source: " + this.Source);
Console.WriteLine();
}
}
class Fabric {
public List<Claim> Claims;
private int[,] Board;
public Fabric(List<Claim> claims) {
this.Claims = claims;
this.Board = new int[10000, 10000];
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
Board[i, j] = 0;
}
}
}
public int CalculateOverlaps() {
int overlaps = 0;
foreach (Claim claim in this.Claims) {
for (int x = claim.X; x < claim.X + claim.W; x++) {
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
Board[x, y]++;
}
}
}
foreach (Claim claim in this.Claims) {
bool isValid = true;
Console.WriteLine("Processing claim ID: " + claim.ID);
for (int x = claim.X; x < claim.X + claim.W; x++) {
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
if(this.Board[x,y] != 1) {
isValid = false;
break;
}
}
if (!isValid) break;
}
if (isValid) {
overlaps = claim.ID;
break;
}
}
return overlaps;
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace challenge2 {
class Program {
static string[] Lines {get; set;}
static List<Claim> Claims {get; set;}
static void Main(string[] args) {
Claims = new List<Claim>();
Console.WriteLine("Reading input.txt");
Lines = File.ReadAllLines("./input.txt");
foreach (string line in Lines) {
Claim current = new Claim(line);
Claims.Add(current);
current.Print();
}
Fabric fabric = new Fabric(Claims);
Console.WriteLine("Found ID: " + fabric.CalculateOverlaps());
}
public static void printArray(string[] arr) {
foreach (string str in arr) {
Console.WriteLine(str);
}
}
}
class Claim {
public int ID {get; set;}
public int X {get; set;}
public int Y {get; set;}
public int W {get; set;}
public int H {get; set;}
public string Source {get; set;}
public Claim(string source) {
this.Source = source;
ParseSource();
}
private void ParseSource() {
Console.WriteLine("Parsing: " + this.Source);
string[] source = this.Source.Split('#');
string[] idAndRest = source[1].Split('@');
this.ID = int.Parse(idAndRest[0]);
string[] fromSides = idAndRest[1].Split(',');
string[] afterColon = fromSides[1].Split(':');
this.X = int.Parse(fromSides[0]);
this.Y = int.Parse(afterColon[0]);
string[] dimensions = afterColon[1].Split('x');
this.W = int.Parse(dimensions[0]);
this.H = int.Parse(dimensions[1]);
}
public void Print() {
Console.WriteLine("Claim ID: " + this.ID);
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
Console.WriteLine("Parsed from source: " + this.Source);
Console.WriteLine();
}
}
class Fabric {
public List<Claim> Claims;
private int[,] Board;
public Fabric(List<Claim> claims) {
this.Claims = claims;
this.Board = new int[10000, 10000];
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
Board[i, j] = 0;
}
}
}
public int CalculateOverlaps() {
int overlaps = 0;
foreach (Claim claim in this.Claims) {
for (int x = claim.X; x < claim.X + claim.W; x++) {
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
Board[x, y]++;
}
}
}
foreach (Claim claim in this.Claims) {
bool isValid = true;
Console.WriteLine("Processing claim ID: " + claim.ID);
for (int x = claim.X; x < claim.X + claim.W; x++) {
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
if(this.Board[x,y] != 1) {
isValid = false;
break;
}
}
if (!isValid) break;
}
if (isValid) {
overlaps = claim.ID;
break;
}
}
return overlaps;
}
}
}

View File

@@ -1,11 +1,11 @@
Your puzzle answer was 109143.
The first half of this puzzle is complete! It provides one gold star: *
--- 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.
Your puzzle answer was 109143.
The first half of this puzzle is complete! It provides one gold star: *
--- 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?

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@@ -1,37 +1,37 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp"
}
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp"
}
}

View File

@@ -1,49 +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.
--- 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.)

View File

@@ -1,71 +1,71 @@
class Guard {
constructor (id) {
this.id = id;
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
this.fellAsleepAt = null;
}
sleep (fellAsleepAt) {
this.fellAsleepAt = fellAsleepAt;
}
awake (awokeAt) {
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
this.minutesAsleep[i] += 1;
}
}
get totalSleepMinutes () {
return this.minutesAsleep.reduce((a, b) => a + b, 0);
}
get sleepiestMinute () {
return this.minutesAsleep
.map((value, index) => ({ index, value }))
.sort((a, b) => b.value - a.value)[0].index;
}
}
const sleep = (input) => {
const guards = {};
const schedule = input
.split('\n')
.map((x) => x.trim())
.sort()
.map((x) => {
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
return {
minute: +parts[5],
message: parts[6],
};
});
let currentGuard = null;
for (let i = 0; i < schedule.length; i++) {
const { message, minute } = schedule[i];
if (/Guard/.test(message)) {
const parts = message.match(/Guard #(\d+) begins shift/);
const guardId = +parts[1];
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
currentGuard = guards[guardId] = guard;
} else if (message === 'falls asleep') {
currentGuard.sleep(minute);
} else if (message === 'wakes up') {
currentGuard.awake(minute);
}
}
const sleepiestGuard = Object
.keys(guards)
.map((guardId) => guards[guardId])
.sort((a, b) => b.totalSleepMinutes - a.totalSleepMinutes)[0];
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
}
const fs = require('fs');
console.log(sleep(fs.readFileSync("input.txt").toString()));
class Guard {
constructor (id) {
this.id = id;
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
this.fellAsleepAt = null;
}
sleep (fellAsleepAt) {
this.fellAsleepAt = fellAsleepAt;
}
awake (awokeAt) {
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
this.minutesAsleep[i] += 1;
}
}
get totalSleepMinutes () {
return this.minutesAsleep.reduce((a, b) => a + b, 0);
}
get sleepiestMinute () {
return this.minutesAsleep
.map((value, index) => ({ index, value }))
.sort((a, b) => b.value - a.value)[0].index;
}
}
const sleep = (input) => {
const guards = {};
const schedule = input
.split('\n')
.map((x) => x.trim())
.sort()
.map((x) => {
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
return {
minute: +parts[5],
message: parts[6],
};
});
let currentGuard = null;
for (let i = 0; i < schedule.length; i++) {
const { message, minute } = schedule[i];
if (/Guard/.test(message)) {
const parts = message.match(/Guard #(\d+) begins shift/);
const guardId = +parts[1];
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
currentGuard = guards[guardId] = guard;
} else if (message === 'falls asleep') {
currentGuard.sleep(minute);
} else if (message === 'wakes up') {
currentGuard.awake(minute);
}
}
const sleepiestGuard = Object
.keys(guards)
.map((guardId) => guards[guardId])
.sort((a, b) => b.totalSleepMinutes - a.totalSleepMinutes)[0];
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
}
const fs = require('fs');
console.log(sleep(fs.readFileSync("input.txt").toString()));

File diff suppressed because it is too large Load Diff

View File

@@ -1,180 +1,180 @@
#include <algorithm>
#include <iterator>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <iomanip>
enum class State {begin, sleep, awaken};
struct Action
{
State state;
int64_t guard_id;
};
struct Event
{
int64_t month, day, hour, minute;
Action action;
};
std::istream &operator>>(std::istream &is, Action &action)
{
std::string element;
is >> element;
if(element=="Guard")
{
action.state=State::begin;
char c;
is >> c >> action.guard_id;
}
else if(element=="falls")
{
action.state=State::sleep;
}
else if(element=="wakes")
{
action.state=State::awaken;
}
else
{
throw std::runtime_error("Invalid input");
}
std::getline(is,element);
return is;
}
std::istream &operator>>(std::istream &is, Event &event)
{
char c;
int64_t year;
is >> c;
if(is.good())
{
is >> year >> c >> event.month >> c >> event.day
>> event.hour >> c >> event.minute >> c
>> event.action;
if(event.hour==23)
{
event.minute=0;
}
}
return is;
}
std::ostream &operator<<(std::ostream &os, const Action &action)
{
switch(action.state)
{
case State::begin:
os << "Guard #" << action.guard_id << " begins shift";
break;
case State::sleep:
os << "falls asleep";
break;
case State::awaken:
os << "wakes up";
break;
default:
os << "What?";
break;
}
return os;
}
std::ostream &operator<<(std::ostream &os, const Event &event)
{
os << "[1518-"
<< std::setw(2) << std::setfill('0') << event.month << "-"
<< std::setw(2) << std::setfill('0') << event.day << " "
<< std::setw(2) << std::setfill('0') << event.hour << ":"
<< std::setw(2) << std::setfill('0') << event.minute << "] "
<< event.action;
return os;
}
std::pair<int64_t,int64_t> max_incident(const std::vector<std::pair<int64_t,
int64_t>> &incidents)
{
std::vector<int64_t> sleep_incidents(60,0);
for(auto &times: incidents)
{
for(size_t time=times.first; time<times.second; ++time)
{ ++(sleep_incidents[time]); }
}
int64_t max_incidents(0), max_minute(0);
for(size_t time=0; time<sleep_incidents.size(); ++time)
{
if(max_incidents<sleep_incidents[time])
{
max_incidents=sleep_incidents[time];
max_minute=time;
}
}
return std::make_pair(max_incidents,max_minute);
}
int main(int argc, char *argv[])
{
std::ifstream infile(argv[1]);
std::vector<Event> events(std::istream_iterator<Event>(infile), {});
std::map<int,std::vector<std::pair<int64_t,int64_t>>> guards;
int64_t guard_id;
int64_t start(-1);
for(auto &event: events)
{
switch(event.action.state)
{
case State::begin:
guard_id=event.action.guard_id;
break;
case State::sleep:
start=event.minute;
break;
case State::awaken:
guards[guard_id].emplace_back(start,event.minute);
break;
}
}
int64_t max_time_guard, max_time(0);
for(auto &guard: guards)
{
int64_t total_time(0);
for(auto &time: guard.second)
{
total_time+=time.second-time.first;
}
if(total_time>max_time)
{
max_time_guard=guard.first;
max_time=total_time;
}
}
auto [max_incidents,max_minute]=max_incident(guards[max_time_guard]);
std::cout << "Part 1: " << (max_minute*max_time_guard) << "\n";
std::vector<int64_t> num_incidents(guards.size());
int64_t max_guard_incidents(0), max_guard_minute(0), max_guard_id(-1);
for(auto &guard: guards)
{
auto [incidents,minute]=max_incident(guard.second);
if(incidents>max_guard_incidents)
{
max_guard_incidents=incidents;
max_guard_minute=minute;
max_guard_id=guard.first;
}
}
std::cout << "Part 2: " << (max_guard_id * max_guard_minute) << "\n";
#include <algorithm>
#include <iterator>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <iomanip>
enum class State {begin, sleep, awaken};
struct Action
{
State state;
int64_t guard_id;
};
struct Event
{
int64_t month, day, hour, minute;
Action action;
};
std::istream &operator>>(std::istream &is, Action &action)
{
std::string element;
is >> element;
if(element=="Guard")
{
action.state=State::begin;
char c;
is >> c >> action.guard_id;
}
else if(element=="falls")
{
action.state=State::sleep;
}
else if(element=="wakes")
{
action.state=State::awaken;
}
else
{
throw std::runtime_error("Invalid input");
}
std::getline(is,element);
return is;
}
std::istream &operator>>(std::istream &is, Event &event)
{
char c;
int64_t year;
is >> c;
if(is.good())
{
is >> year >> c >> event.month >> c >> event.day
>> event.hour >> c >> event.minute >> c
>> event.action;
if(event.hour==23)
{
event.minute=0;
}
}
return is;
}
std::ostream &operator<<(std::ostream &os, const Action &action)
{
switch(action.state)
{
case State::begin:
os << "Guard #" << action.guard_id << " begins shift";
break;
case State::sleep:
os << "falls asleep";
break;
case State::awaken:
os << "wakes up";
break;
default:
os << "What?";
break;
}
return os;
}
std::ostream &operator<<(std::ostream &os, const Event &event)
{
os << "[1518-"
<< std::setw(2) << std::setfill('0') << event.month << "-"
<< std::setw(2) << std::setfill('0') << event.day << " "
<< std::setw(2) << std::setfill('0') << event.hour << ":"
<< std::setw(2) << std::setfill('0') << event.minute << "] "
<< event.action;
return os;
}
std::pair<int64_t,int64_t> max_incident(const std::vector<std::pair<int64_t,
int64_t>> &incidents)
{
std::vector<int64_t> sleep_incidents(60,0);
for(auto &times: incidents)
{
for(size_t time=times.first; time<times.second; ++time)
{ ++(sleep_incidents[time]); }
}
int64_t max_incidents(0), max_minute(0);
for(size_t time=0; time<sleep_incidents.size(); ++time)
{
if(max_incidents<sleep_incidents[time])
{
max_incidents=sleep_incidents[time];
max_minute=time;
}
}
return std::make_pair(max_incidents,max_minute);
}
int main(int argc, char *argv[])
{
std::ifstream infile(argv[1]);
std::vector<Event> events(std::istream_iterator<Event>(infile), {});
std::map<int,std::vector<std::pair<int64_t,int64_t>>> guards;
int64_t guard_id;
int64_t start(-1);
for(auto &event: events)
{
switch(event.action.state)
{
case State::begin:
guard_id=event.action.guard_id;
break;
case State::sleep:
start=event.minute;
break;
case State::awaken:
guards[guard_id].emplace_back(start,event.minute);
break;
}
}
int64_t max_time_guard, max_time(0);
for(auto &guard: guards)
{
int64_t total_time(0);
for(auto &time: guard.second)
{
total_time+=time.second-time.first;
}
if(total_time>max_time)
{
max_time_guard=guard.first;
max_time=total_time;
}
}
auto [max_incidents,max_minute]=max_incident(guards[max_time_guard]);
std::cout << "Part 1: " << (max_minute*max_time_guard) << "\n";
std::vector<int64_t> num_incidents(guards.size());
int64_t max_guard_incidents(0), max_guard_minute(0), max_guard_id(-1);
for(auto &guard: guards)
{
auto [incidents,minute]=max_incident(guard.second);
if(incidents>max_guard_incidents)
{
max_guard_incidents=incidents;
max_guard_minute=minute;
max_guard_id=guard.first;
}
}
std::cout << "Part 2: " << (max_guard_id * max_guard_minute) << "\n";
}

View File

@@ -1,7 +1,7 @@
--- Part Two ---
Strategy 2: Of all guards, which guard is most frequently asleep on the same minute?
In the example above, Guard #99 spent minute 45 asleep more than any other guard or minute - three times in total. (In all other cases, any guard spent any minute asleep at most twice.)
What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 99 * 45 = 4455.)
--- Part Two ---
Strategy 2: Of all guards, which guard is most frequently asleep on the same minute?
In the example above, Guard #99 spent minute 45 asleep more than any other guard or minute - three times in total. (In all other cases, any guard spent any minute asleep at most twice.)
What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 99 * 45 = 4455.)

View File

@@ -1,68 +1,68 @@
class Guard {
constructor (id) {
this.id = id;
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
this.fellAsleepAt = null;
}
sleep (fellAsleepAt) {
this.fellAsleepAt = fellAsleepAt;
}
awake (awokeAt) {
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
this.minutesAsleep[i] += 1;
}
}
get sleepiestMinute () {
return this.minutesAsleep
.map((value, index) => ({ index, value }))
.sort((a, b) => b.value - a.value)[0].index;
}
}
const sleep = (input) => {
const guards = {};
const schedule = input
.split('\n')
.map((x) => x.trim())
.sort()
.map((x) => {
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
return {
minute: +parts[5],
message: parts[6],
};
});
let currentGuard = null;
for (let i = 0; i < schedule.length; i++) {
const { message, minute } = schedule[i];
if (/Guard/.test(message)) {
const parts = message.match(/Guard #(\d+) begins shift/);
const guardId = +parts[1];
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
currentGuard = guards[guardId] = guard;
} else if (message === 'falls asleep') {
currentGuard.sleep(minute);
} else if (message === 'wakes up') {
currentGuard.awake(minute);
}
}
const sleepiestGuard = Object
.keys(guards)
.map((guardId) => guards[guardId])
.sort((a, b) => b.minutesAsleep[b.sleepiestMinute] -
a.minutesAsleep[a.sleepiestMinute])[0];
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
};
const fs = require('fs');
console.log(sleep(fs.readFileSync("input.txt").toString()));
class Guard {
constructor (id) {
this.id = id;
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
this.fellAsleepAt = null;
}
sleep (fellAsleepAt) {
this.fellAsleepAt = fellAsleepAt;
}
awake (awokeAt) {
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
this.minutesAsleep[i] += 1;
}
}
get sleepiestMinute () {
return this.minutesAsleep
.map((value, index) => ({ index, value }))
.sort((a, b) => b.value - a.value)[0].index;
}
}
const sleep = (input) => {
const guards = {};
const schedule = input
.split('\n')
.map((x) => x.trim())
.sort()
.map((x) => {
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
return {
minute: +parts[5],
message: parts[6],
};
});
let currentGuard = null;
for (let i = 0; i < schedule.length; i++) {
const { message, minute } = schedule[i];
if (/Guard/.test(message)) {
const parts = message.match(/Guard #(\d+) begins shift/);
const guardId = +parts[1];
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
currentGuard = guards[guardId] = guard;
} else if (message === 'falls asleep') {
currentGuard.sleep(minute);
} else if (message === 'wakes up') {
currentGuard.awake(minute);
}
}
const sleepiestGuard = Object
.keys(guards)
.map((guardId) => guards[guardId])
.sort((a, b) => b.minutesAsleep[b.sleepiestMinute] -
a.minutesAsleep[a.sleepiestMinute])[0];
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
};
const fs = require('fs');
console.log(sleep(fs.readFileSync("input.txt").toString()));

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
{
"files.associations": {
"ostream": "cpp"
}
{
"files.associations": {
"ostream": "cpp"
}
}

View File

@@ -1,22 +1,22 @@
--- Day 5: Alchemical Reduction ---
You've managed to sneak in to the prototype suit manufacturing lab. The Elves are making decent progress, but are still struggling with the suit's size reduction capabilities.
While the very latest in 1518 alchemical technology might have solved their problem eventually, you can do better. You scan the chemical composition of the suit's material and discover that it is formed by extremely long polymers (one of which is available as your puzzle input).
The polymer is formed by smaller units which, when triggered, react with each other such that two adjacent units of the same type and opposite polarity are destroyed. Units' types are represented by letters; units' polarity is represented by capitalization. For instance, r and R are units with the same type but opposite polarity, whereas r and s are entirely different types and do not react.
For example:
In aA, a and A react, leaving nothing behind.
In abBA, bB destroys itself, leaving aA. As above, this then destroys itself, leaving nothing.
In abAB, no two adjacent units are of the same type, and so nothing happens.
In aabAAB, even though aa and AA are of the same type, their polarities match, and so nothing happens.
Now, consider a larger example, dabAcCaCBAcCcaDA:
dabAcCaCBAcCcaDA The first 'cC' is removed.
dabAaCBAcCcaDA This creates 'Aa', which is removed.
dabCBAcCcaDA Either 'cC' or 'Cc' are removed (the result is the same).
dabCBAcaDA No further actions can be taken.
After all possible reactions, the resulting polymer contains 10 units.
--- Day 5: Alchemical Reduction ---
You've managed to sneak in to the prototype suit manufacturing lab. The Elves are making decent progress, but are still struggling with the suit's size reduction capabilities.
While the very latest in 1518 alchemical technology might have solved their problem eventually, you can do better. You scan the chemical composition of the suit's material and discover that it is formed by extremely long polymers (one of which is available as your puzzle input).
The polymer is formed by smaller units which, when triggered, react with each other such that two adjacent units of the same type and opposite polarity are destroyed. Units' types are represented by letters; units' polarity is represented by capitalization. For instance, r and R are units with the same type but opposite polarity, whereas r and s are entirely different types and do not react.
For example:
In aA, a and A react, leaving nothing behind.
In abBA, bB destroys itself, leaving aA. As above, this then destroys itself, leaving nothing.
In abAB, no two adjacent units are of the same type, and so nothing happens.
In aabAAB, even though aa and AA are of the same type, their polarities match, and so nothing happens.
Now, consider a larger example, dabAcCaCBAcCcaDA:
dabAcCaCBAcCcaDA The first 'cC' is removed.
dabAaCBAcCcaDA This creates 'Aa', which is removed.
dabCBAcCcaDA Either 'cC' or 'Cc' are removed (the result is the same).
dabCBAcaDA No further actions can be taken.
After all possible reactions, the resulting polymer contains 10 units.
How many units remain after fully reacting the polymer you scanned? (Note: in this puzzle and others, the input is large; if you copy/paste your input, make sure you get the whole thing.)

View File

@@ -1,5 +1,5 @@
const day4 = require('./istolethisfromsomeone');
const fs = require('fs');
console.log('Part 1: ' + day4.part1(fs.readFileSync('input.txt').toString()));
console.log('Part 2: ' + day4.part2(fs.readFileSync('input.txt').toString()));
const day4 = require('./istolethisfromsomeone');
const fs = require('fs');
console.log('Part 1: ' + day4.part1(fs.readFileSync('input.txt').toString()));
console.log('Part 2: ' + day4.part2(fs.readFileSync('input.txt').toString()));

File diff suppressed because one or more lines are too long

View File

@@ -1,44 +1,44 @@
function part1(data) {
const polymer = data.split("");
const removeChar = ""; // No removal
const stack = collapsePloymer(polymer, removeChar);
return stack.length;
}
function collapsePloymer(ploymerChars, removeChar) {
const stack = [];
for (let i = 0; i < ploymerChars.length; i++) {
const char = ploymerChars[i];
if (char.toLowerCase() === removeChar.toLowerCase()) {
continue;
}
const last = stack.pop();
if (!last) {
stack.push(char);
continue;
}
if (last.toLowerCase() === char.toLowerCase() && last !== char) {
continue;
}
stack.push(last);
stack.push(char);
}
return stack;
}
function part2(data) {
const polymer = data.split("");
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
const collapsedPolymers = alphabet.map(letter =>
collapsePloymer(polymer, letter)
);
const shortestCollapse = collapsedPolymers.reduce((longest, curr) =>
longest.length < curr.length ? longest : curr
);
return shortestCollapse.length;
}
module.exports = {
part1: part1,
part2: part2
function part1(data) {
const polymer = data.split("");
const removeChar = ""; // No removal
const stack = collapsePloymer(polymer, removeChar);
return stack.length;
}
function collapsePloymer(ploymerChars, removeChar) {
const stack = [];
for (let i = 0; i < ploymerChars.length; i++) {
const char = ploymerChars[i];
if (char.toLowerCase() === removeChar.toLowerCase()) {
continue;
}
const last = stack.pop();
if (!last) {
stack.push(char);
continue;
}
if (last.toLowerCase() === char.toLowerCase() && last !== char) {
continue;
}
stack.push(last);
stack.push(char);
}
return stack;
}
function part2(data) {
const polymer = data.split("");
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
const collapsedPolymers = alphabet.map(letter =>
collapsePloymer(polymer, letter)
);
const shortestCollapse = collapsedPolymers.reduce((longest, curr) =>
longest.length < curr.length ? longest : curr
);
return shortestCollapse.length;
}
module.exports = {
part1: part1,
part2: part2
};

View File

@@ -1,43 +1,43 @@
#include <iostream>
#include <fstream>
#include <string.h>
int main(int argc, char** argv) {
if (argc != 2) return 0;
std::fstream input;
input.open(*(argv + 1));
std::string polymerString;
std::getline(input, polymerString);
while (!false) {
int numOfMods = 0;
std::string eh = "";
for (unsigned int i = 0; i < polymerString.length() - 1; i++) {
if (islower((char)polymerString[i])) {
if (toupper((char)polymerString[i]) == (char)polymerString[i+1]) {
eh += polymerString.substr(0, i);
eh += polymerString.substr(i + 2, polymerString.length());
numOfMods++;
break;
}
}
if (isupper((char)polymerString[i])) {
if (tolower((char)polymerString[i]) == (char)polymerString[i+1]) {
eh += polymerString.substr(0, i);
eh += polymerString.substr(i + 2, polymerString.length());
numOfMods++;
break;
}
}
}
if (eh != "") {
polymerString = eh;
}
std::cout << "Current length: " <<polymerString.length() << std::endl;
if (numOfMods == 0) break;
}
std::cout << "Found polymers: " << polymerString << std::endl;
std::cout << "At length: " << polymerString.length() << std::endl;
}
#include <iostream>
#include <fstream>
#include <string.h>
int main(int argc, char** argv) {
if (argc != 2) return 0;
std::fstream input;
input.open(*(argv + 1));
std::string polymerString;
std::getline(input, polymerString);
while (!false) {
int numOfMods = 0;
std::string eh = "";
for (unsigned int i = 0; i < polymerString.length() - 1; i++) {
if (islower((char)polymerString[i])) {
if (toupper((char)polymerString[i]) == (char)polymerString[i+1]) {
eh += polymerString.substr(0, i);
eh += polymerString.substr(i + 2, polymerString.length());
numOfMods++;
break;
}
}
if (isupper((char)polymerString[i])) {
if (tolower((char)polymerString[i]) == (char)polymerString[i+1]) {
eh += polymerString.substr(0, i);
eh += polymerString.substr(i + 2, polymerString.length());
numOfMods++;
break;
}
}
}
if (eh != "") {
polymerString = eh;
}
std::cout << "Current length: " <<polymerString.length() << std::endl;
if (numOfMods == 0) break;
}
std::cout << "Found polymers: " << polymerString << std::endl;
std::cout << "At length: " << polymerString.length() << std::endl;
}

View File

@@ -1,14 +1,14 @@
--- Part Two ---
Time to improve the polymer.
One of the unit types is causing problems; it's preventing the polymer from collapsing as much as it should. Your goal is to figure out which unit type is causing the most problems, remove all instances of it (regardless of polarity), fully react the remaining polymer, and measure its length.
For example, again using the polymer dabAcCaCBAcCcaDA from above:
Removing all A/a units produces dbcCCBcCcD. Fully reacting this polymer produces dbCBcD, which has length 6.
Removing all B/b units produces daAcCaCAcCcaDA. Fully reacting this polymer produces daCAcaDA, which has length 8.
Removing all C/c units produces dabAaBAaDA. Fully reacting this polymer produces daDA, which has length 4.
Removing all D/d units produces abAcCaCBAcCcaA. Fully reacting this polymer produces abCBAc, which has length 6.
In this example, removing all C/c units was best, producing the answer 4.
What is the length of the shortest polymer you can produce by removing all units of exactly one type and fully reacting the result?
--- Part Two ---
Time to improve the polymer.
One of the unit types is causing problems; it's preventing the polymer from collapsing as much as it should. Your goal is to figure out which unit type is causing the most problems, remove all instances of it (regardless of polarity), fully react the remaining polymer, and measure its length.
For example, again using the polymer dabAcCaCBAcCcaDA from above:
Removing all A/a units produces dbcCCBcCcD. Fully reacting this polymer produces dbCBcD, which has length 6.
Removing all B/b units produces daAcCaCAcCcaDA. Fully reacting this polymer produces daCAcaDA, which has length 8.
Removing all C/c units produces dabAaBAaDA. Fully reacting this polymer produces daDA, which has length 4.
Removing all D/d units produces abAcCaCBAcCcaA. Fully reacting this polymer produces abCBAc, which has length 6.
In this example, removing all C/c units was best, producing the answer 4.
What is the length of the shortest polymer you can produce by removing all units of exactly one type and fully reacting the result?

File diff suppressed because one or more lines are too long

View File

@@ -1,81 +1,81 @@
--- Day 6: Chronal Coordinates ---
The device on your wrist beeps several times, and once again you feel like you're falling.
"Situation critical," the device announces. "Destination indeterminate. Chronal interference detected. Please specify new target coordinates."
The device then produces a list of coordinates (your puzzle input). Are they places it thinks are safe or dangerous? It recommends you check manual page 729. The Elves did not give you a manual.
If they're dangerous, maybe you can minimize the danger by finding the coordinate that gives the largest distance from the other points.
Using only the Manhattan distance, determine the area around each coordinate by counting the number of integer X,Y locations that are closest to that coordinate (and aren't tied in distance to any other coordinate).
Your goal is to find the size of the largest area that isn't infinite. For example, consider the following list of coordinates:
1, 1
1, 6
8, 3
3, 4
5, 5
8, 9
If we name these coordinates A through F, we can draw them on a grid, putting 0,0 at the top left:
..........
.A........
..........
........C.
...D......
.....E....
.B........
..........
..........
........F.
This view is partial - the actual grid extends infinitely in all directions. Using the Manhattan distance, each location's closest coordinate can be determined, shown here in lowercase:
aaaaa.cccc
aAaaa.cccc
aaaddecccc
aadddeccCc
..dDdeeccc
bb.deEeecc
bBb.eeee..
bbb.eeefff
bbb.eeffff
bbb.ffffFf
Locations shown as . are equally far from two or more coordinates, and so they don't count as being closest to any.
In this example, the areas of coordinates A, B, C, and F are infinite - while not shown here, their areas extend forever outside the visible grid. However, the areas of coordinates D and E are finite: D is closest to 9 locations, and E is closest to 17 (both including the coordinate's location itself). Therefore, in this example, the size of the largest area is 17.
What is the size of the largest area that isn't infinite?
--- Part Two ---
On the other hand, if the coordinates are safe, maybe the best you can do is try to find a region near as many coordinates as possible.
For example, suppose you want the sum of the Manhattan distance to all of the coordinates to be less than 32. For each location, add up the distances to all of the given coordinates; if the total of those distances is less than 32, that location is within the desired region. Using the same coordinates as above, the resulting region looks like this:
..........
.A........
..........
...###..C.
..#D###...
..###E#...
.B.###....
..........
..........
........F.
In particular, consider the highlighted location 4,3 located at the top middle of the region. Its calculation is as follows, where abs() is the absolute value function:
Distance to coordinate A: abs(4-1) + abs(3-1) = 5
Distance to coordinate B: abs(4-1) + abs(3-6) = 6
Distance to coordinate C: abs(4-8) + abs(3-3) = 4
Distance to coordinate D: abs(4-3) + abs(3-4) = 2
Distance to coordinate E: abs(4-5) + abs(3-5) = 3
Distance to coordinate F: abs(4-8) + abs(3-9) = 10
Total distance: 5 + 6 + 4 + 2 + 3 + 10 = 30
Because the total distance to all coordinates (30) is less than 32, the location is within the region.
This region, which also includes coordinates D and E, has a total size of 16.
Your actual region will need to be much larger than this example, though, instead including all locations with a total distance of less than 10000.
What is the size of the region containing all locations which have a total distance to all given coordinates of less than 10000?
--- Day 6: Chronal Coordinates ---
The device on your wrist beeps several times, and once again you feel like you're falling.
"Situation critical," the device announces. "Destination indeterminate. Chronal interference detected. Please specify new target coordinates."
The device then produces a list of coordinates (your puzzle input). Are they places it thinks are safe or dangerous? It recommends you check manual page 729. The Elves did not give you a manual.
If they're dangerous, maybe you can minimize the danger by finding the coordinate that gives the largest distance from the other points.
Using only the Manhattan distance, determine the area around each coordinate by counting the number of integer X,Y locations that are closest to that coordinate (and aren't tied in distance to any other coordinate).
Your goal is to find the size of the largest area that isn't infinite. For example, consider the following list of coordinates:
1, 1
1, 6
8, 3
3, 4
5, 5
8, 9
If we name these coordinates A through F, we can draw them on a grid, putting 0,0 at the top left:
..........
.A........
..........
........C.
...D......
.....E....
.B........
..........
..........
........F.
This view is partial - the actual grid extends infinitely in all directions. Using the Manhattan distance, each location's closest coordinate can be determined, shown here in lowercase:
aaaaa.cccc
aAaaa.cccc
aaaddecccc
aadddeccCc
..dDdeeccc
bb.deEeecc
bBb.eeee..
bbb.eeefff
bbb.eeffff
bbb.ffffFf
Locations shown as . are equally far from two or more coordinates, and so they don't count as being closest to any.
In this example, the areas of coordinates A, B, C, and F are infinite - while not shown here, their areas extend forever outside the visible grid. However, the areas of coordinates D and E are finite: D is closest to 9 locations, and E is closest to 17 (both including the coordinate's location itself). Therefore, in this example, the size of the largest area is 17.
What is the size of the largest area that isn't infinite?
--- Part Two ---
On the other hand, if the coordinates are safe, maybe the best you can do is try to find a region near as many coordinates as possible.
For example, suppose you want the sum of the Manhattan distance to all of the coordinates to be less than 32. For each location, add up the distances to all of the given coordinates; if the total of those distances is less than 32, that location is within the desired region. Using the same coordinates as above, the resulting region looks like this:
..........
.A........
..........
...###..C.
..#D###...
..###E#...
.B.###....
..........
..........
........F.
In particular, consider the highlighted location 4,3 located at the top middle of the region. Its calculation is as follows, where abs() is the absolute value function:
Distance to coordinate A: abs(4-1) + abs(3-1) = 5
Distance to coordinate B: abs(4-1) + abs(3-6) = 6
Distance to coordinate C: abs(4-8) + abs(3-3) = 4
Distance to coordinate D: abs(4-3) + abs(3-4) = 2
Distance to coordinate E: abs(4-5) + abs(3-5) = 3
Distance to coordinate F: abs(4-8) + abs(3-9) = 10
Total distance: 5 + 6 + 4 + 2 + 3 + 10 = 30
Because the total distance to all coordinates (30) is less than 32, the location is within the region.
This region, which also includes coordinates D and E, has a total size of 16.
Your actual region will need to be much larger than this example, though, instead including all locations with a total distance of less than 10000.
What is the size of the region containing all locations which have a total distance to all given coordinates of less than 10000?

View File

@@ -1,50 +1,50 @@
194, 200
299, 244
269, 329
292, 55
211, 63
123, 311
212, 90
292, 169
359, 177
354, 95
101, 47
95, 79
95, 287
294, 126
81, 267
330, 78
202, 165
225, 178
266, 272
351, 326
180, 62
102, 178
151, 101
343, 145
205, 312
74, 193
221, 56
89, 89
242, 172
59, 138
83, 179
223, 88
297, 234
147, 351
226, 320
358, 338
321, 172
54, 122
263, 165
126, 341
64, 132
264, 306
72, 202
98, 49
238, 67
310, 303
277, 281
222, 318
357, 169
194, 200
299, 244
269, 329
292, 55
211, 63
123, 311
212, 90
292, 169
359, 177
354, 95
101, 47
95, 79
95, 287
294, 126
81, 267
330, 78
202, 165
225, 178
266, 272
351, 326
180, 62
102, 178
151, 101
343, 145
205, 312
74, 193
221, 56
89, 89
242, 172
59, 138
83, 179
223, 88
297, 234
147, 351
226, 320
358, 338
321, 172
54, 122
263, 165
126, 341
64, 132
264, 306
72, 202
98, 49
238, 67
310, 303
277, 281
222, 318
357, 169
123, 225

View File

@@ -1,131 +1,131 @@
#include <algorithm>
#include <iterator>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
struct Point
{
int64_t x, y;
Point(const int64_t &X, const int64_t &Y) : x(X), y(Y) {}
Point() = default;
};
int64_t distance(const Point &a, const Point &b)
{
return std::abs(a.x - b.x) + std::abs(a.y - b.y);
}
std::istream &operator>>(std::istream &is, Point &p)
{
char c;
is >> p.x >> c >> p.y;
return is;
}
std::ostream &operator<<(std::ostream &os, Point &p)
{
char c;
os << p.x << ", " << p.y;
return os;
}
size_t min_index(const size_t &invalid, const Point &point,
const std::vector<Point> &points)
{
size_t result;
int64_t min_dist(std::numeric_limits<int64_t>::max());
for(size_t p = 0; p < points.size(); ++p)
{
int64_t d(distance(point, points[p]));
if(min_dist > d)
{
min_dist = d;
result = p;
}
else if(min_dist == d)
{
result = invalid;
}
}
return result;
}
int main(int argc, char *argv[])
{
std::ifstream infile(argv[1]);
std::vector<Point> points(std::istream_iterator<Point>(infile), {});
int64_t min_x(std::numeric_limits<int64_t>::max()), min_y(min_x),
max_x(std::numeric_limits<int64_t>::min()), max_y(max_x);
for(auto &p : points)
{
min_x = std::min(min_x, p.x);
min_y = std::min(min_y, p.y);
max_x = std::max(max_x, p.x);
max_y = std::max(max_y, p.y);
}
int64_t width(max_x - min_x + 1), height(max_y - min_y + 1);
const size_t invalid(points.size());
std::vector<int64_t> num_claimed(points.size() + 1, 0);
std::set<size_t> invalid_points;
for(int64_t x = min_x; x <= max_x; ++x)
{
invalid_points.insert(min_index(invalid, Point(x, min_y), points));
invalid_points.insert(min_index(invalid, Point(x, max_y), points));
}
for(int64_t y = min_y; y <= max_y; ++y)
{
invalid_points.insert(min_index(invalid, Point(min_x, y), points));
invalid_points.insert(min_index(invalid, Point(max_x, y), points));
}
for(int64_t x = 0; x < width; ++x)
for(int64_t y = 0; y < height; ++y)
{
int64_t min_dist(std::numeric_limits<int64_t>::max());
size_t min_index;
for(size_t p = 0; p < points.size(); ++p)
{
int64_t d(distance(Point(x + min_x, y + min_y), points[p]));
if(min_dist > d)
{
min_dist = d;
min_index = p;
}
else if(min_dist == d)
{
min_index = invalid;
}
}
if(invalid_points.find(min_index) == invalid_points.end())
++num_claimed[min_index];
}
std::cout << "Part 1: "
<< *std::max_element(num_claimed.begin(), num_claimed.end())
<< "\n";
int64_t area(0);
constexpr int64_t cutoff(10000);
const int64_t padding(cutoff / points.size() + 1);
const int64_t x_lower(min_x - padding), x_upper(max_x + 1 + padding),
y_lower(min_y - padding), y_upper(max_y + 1 + padding);
for(int64_t x = x_lower; x < x_upper; ++x)
for(int64_t y = y_lower; y < y_upper; ++y)
{
int64_t total_dist(0);
for(auto &point : points)
{
total_dist += distance(Point(x, y), point);
if(total_dist > cutoff)
break;
}
if(total_dist < cutoff)
++area;
}
std::cout << "Part 2: " << area << "\n";
#include <algorithm>
#include <iterator>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
struct Point
{
int64_t x, y;
Point(const int64_t &X, const int64_t &Y) : x(X), y(Y) {}
Point() = default;
};
int64_t distance(const Point &a, const Point &b)
{
return std::abs(a.x - b.x) + std::abs(a.y - b.y);
}
std::istream &operator>>(std::istream &is, Point &p)
{
char c;
is >> p.x >> c >> p.y;
return is;
}
std::ostream &operator<<(std::ostream &os, Point &p)
{
char c;
os << p.x << ", " << p.y;
return os;
}
size_t min_index(const size_t &invalid, const Point &point,
const std::vector<Point> &points)
{
size_t result;
int64_t min_dist(std::numeric_limits<int64_t>::max());
for(size_t p = 0; p < points.size(); ++p)
{
int64_t d(distance(point, points[p]));
if(min_dist > d)
{
min_dist = d;
result = p;
}
else if(min_dist == d)
{
result = invalid;
}
}
return result;
}
int main(int argc, char *argv[])
{
std::ifstream infile(argv[1]);
std::vector<Point> points(std::istream_iterator<Point>(infile), {});
int64_t min_x(std::numeric_limits<int64_t>::max()), min_y(min_x),
max_x(std::numeric_limits<int64_t>::min()), max_y(max_x);
for(auto &p : points)
{
min_x = std::min(min_x, p.x);
min_y = std::min(min_y, p.y);
max_x = std::max(max_x, p.x);
max_y = std::max(max_y, p.y);
}
int64_t width(max_x - min_x + 1), height(max_y - min_y + 1);
const size_t invalid(points.size());
std::vector<int64_t> num_claimed(points.size() + 1, 0);
std::set<size_t> invalid_points;
for(int64_t x = min_x; x <= max_x; ++x)
{
invalid_points.insert(min_index(invalid, Point(x, min_y), points));
invalid_points.insert(min_index(invalid, Point(x, max_y), points));
}
for(int64_t y = min_y; y <= max_y; ++y)
{
invalid_points.insert(min_index(invalid, Point(min_x, y), points));
invalid_points.insert(min_index(invalid, Point(max_x, y), points));
}
for(int64_t x = 0; x < width; ++x)
for(int64_t y = 0; y < height; ++y)
{
int64_t min_dist(std::numeric_limits<int64_t>::max());
size_t min_index;
for(size_t p = 0; p < points.size(); ++p)
{
int64_t d(distance(Point(x + min_x, y + min_y), points[p]));
if(min_dist > d)
{
min_dist = d;
min_index = p;
}
else if(min_dist == d)
{
min_index = invalid;
}
}
if(invalid_points.find(min_index) == invalid_points.end())
++num_claimed[min_index];
}
std::cout << "Part 1: "
<< *std::max_element(num_claimed.begin(), num_claimed.end())
<< "\n";
int64_t area(0);
constexpr int64_t cutoff(10000);
const int64_t padding(cutoff / points.size() + 1);
const int64_t x_lower(min_x - padding), x_upper(max_x + 1 + padding),
y_lower(min_y - padding), y_upper(max_y + 1 + padding);
for(int64_t x = x_lower; x < x_upper; ++x)
for(int64_t y = y_lower; y < y_upper; ++y)
{
int64_t total_dist(0);
for(auto &point : points)
{
total_dist += distance(Point(x, y), point);
if(total_dist > cutoff)
break;
}
if(total_dist < cutoff)
++area;
}
std::cout << "Part 2: " << area << "\n";
}