bit behind, so much work
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
.vs/
|
.vs/
|
||||||
.exe/
|
.exe/
|
||||||
.o/
|
.o/
|
||||||
*.o
|
*.o
|
||||||
|
|||||||
114
.vscode/settings.json
vendored
114
.vscode/settings.json
vendored
@@ -1,57 +1,59 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"iosfwd": "cpp",
|
"iosfwd": "cpp",
|
||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"cctype": "cpp",
|
"cctype": "cpp",
|
||||||
"cmath": "cpp",
|
"cmath": "cpp",
|
||||||
"cstddef": "cpp",
|
"cstddef": "cpp",
|
||||||
"cstdint": "cpp",
|
"cstdint": "cpp",
|
||||||
"cstdio": "cpp",
|
"cstdio": "cpp",
|
||||||
"cstdlib": "cpp",
|
"cstdlib": "cpp",
|
||||||
"cstring": "cpp",
|
"cstring": "cpp",
|
||||||
"cwchar": "cpp",
|
"cwchar": "cpp",
|
||||||
"exception": "cpp",
|
"exception": "cpp",
|
||||||
"fstream": "cpp",
|
"fstream": "cpp",
|
||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"ios": "cpp",
|
"ios": "cpp",
|
||||||
"iostream": "cpp",
|
"iostream": "cpp",
|
||||||
"istream": "cpp",
|
"istream": "cpp",
|
||||||
"limits": "cpp",
|
"limits": "cpp",
|
||||||
"memory": "cpp",
|
"memory": "cpp",
|
||||||
"new": "cpp",
|
"new": "cpp",
|
||||||
"ostream": "cpp",
|
"ostream": "cpp",
|
||||||
"sstream": "cpp",
|
"sstream": "cpp",
|
||||||
"stdexcept": "cpp",
|
"stdexcept": "cpp",
|
||||||
"streambuf": "cpp",
|
"streambuf": "cpp",
|
||||||
"string": "cpp",
|
"string": "cpp",
|
||||||
"system_error": "cpp",
|
"system_error": "cpp",
|
||||||
"tuple": "cpp",
|
"tuple": "cpp",
|
||||||
"type_traits": "cpp",
|
"type_traits": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"utility": "cpp",
|
"utility": "cpp",
|
||||||
"xfacet": "cpp",
|
"xfacet": "cpp",
|
||||||
"xiosbase": "cpp",
|
"xiosbase": "cpp",
|
||||||
"xlocale": "cpp",
|
"xlocale": "cpp",
|
||||||
"xlocinfo": "cpp",
|
"xlocinfo": "cpp",
|
||||||
"xlocnum": "cpp",
|
"xlocnum": "cpp",
|
||||||
"xmemory": "cpp",
|
"xmemory": "cpp",
|
||||||
"xmemory0": "cpp",
|
"xmemory0": "cpp",
|
||||||
"xstddef": "cpp",
|
"xstddef": "cpp",
|
||||||
"xstring": "cpp",
|
"xstring": "cpp",
|
||||||
"xtr1common": "cpp",
|
"xtr1common": "cpp",
|
||||||
"xutility": "cpp",
|
"xutility": "cpp",
|
||||||
"algorithm": "cpp",
|
"algorithm": "cpp",
|
||||||
"concepts": "cpp",
|
"concepts": "cpp",
|
||||||
"ctime": "cpp",
|
"ctime": "cpp",
|
||||||
"iomanip": "cpp",
|
"iomanip": "cpp",
|
||||||
"iterator": "cpp",
|
"iterator": "cpp",
|
||||||
"list": "cpp",
|
"list": "cpp",
|
||||||
"map": "cpp",
|
"map": "cpp",
|
||||||
"set": "cpp",
|
"set": "cpp",
|
||||||
"unordered_map": "cpp",
|
"unordered_map": "cpp",
|
||||||
"xhash": "cpp",
|
"xhash": "cpp",
|
||||||
"xlocmon": "cpp",
|
"xlocmon": "cpp",
|
||||||
"xloctime": "cpp",
|
"xloctime": "cpp",
|
||||||
"xtree": "cpp"
|
"xtree": "cpp",
|
||||||
}
|
"atomic": "cpp",
|
||||||
|
"compare": "cpp"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
82
2018/.vscode/settings.json
vendored
82
2018/.vscode/settings.json
vendored
@@ -1,42 +1,42 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"cmath": "cpp",
|
"cmath": "cpp",
|
||||||
"cstddef": "cpp",
|
"cstddef": "cpp",
|
||||||
"cstdint": "cpp",
|
"cstdint": "cpp",
|
||||||
"cstdio": "cpp",
|
"cstdio": "cpp",
|
||||||
"cstdlib": "cpp",
|
"cstdlib": "cpp",
|
||||||
"cstring": "cpp",
|
"cstring": "cpp",
|
||||||
"cwchar": "cpp",
|
"cwchar": "cpp",
|
||||||
"exception": "cpp",
|
"exception": "cpp",
|
||||||
"fstream": "cpp",
|
"fstream": "cpp",
|
||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"ios": "cpp",
|
"ios": "cpp",
|
||||||
"iosfwd": "cpp",
|
"iosfwd": "cpp",
|
||||||
"iostream": "cpp",
|
"iostream": "cpp",
|
||||||
"istream": "cpp",
|
"istream": "cpp",
|
||||||
"limits": "cpp",
|
"limits": "cpp",
|
||||||
"memory": "cpp",
|
"memory": "cpp",
|
||||||
"new": "cpp",
|
"new": "cpp",
|
||||||
"ostream": "cpp",
|
"ostream": "cpp",
|
||||||
"stdexcept": "cpp",
|
"stdexcept": "cpp",
|
||||||
"streambuf": "cpp",
|
"streambuf": "cpp",
|
||||||
"string": "cpp",
|
"string": "cpp",
|
||||||
"system_error": "cpp",
|
"system_error": "cpp",
|
||||||
"tuple": "cpp",
|
"tuple": "cpp",
|
||||||
"type_traits": "cpp",
|
"type_traits": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"utility": "cpp",
|
"utility": "cpp",
|
||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"xfacet": "cpp",
|
"xfacet": "cpp",
|
||||||
"xiosbase": "cpp",
|
"xiosbase": "cpp",
|
||||||
"xlocale": "cpp",
|
"xlocale": "cpp",
|
||||||
"xlocinfo": "cpp",
|
"xlocinfo": "cpp",
|
||||||
"xlocnum": "cpp",
|
"xlocnum": "cpp",
|
||||||
"xmemory": "cpp",
|
"xmemory": "cpp",
|
||||||
"xmemory0": "cpp",
|
"xmemory0": "cpp",
|
||||||
"xstddef": "cpp",
|
"xstddef": "cpp",
|
||||||
"xstring": "cpp",
|
"xstring": "cpp",
|
||||||
"xtr1common": "cpp",
|
"xtr1common": "cpp",
|
||||||
"xutility": "cpp"
|
"xutility": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
--- Day 1: Chronal Calibration ---
|
--- 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!"
|
"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 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.
|
"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!
|
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.
|
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:
|
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 0, change of +1; resulting frequency 1.
|
||||||
Current frequency 1, change of -2; resulting frequency -1.
|
Current frequency 1, change of -2; resulting frequency -1.
|
||||||
Current frequency -1, change of +3; resulting frequency 2.
|
Current frequency -1, change of +3; resulting frequency 2.
|
||||||
Current frequency 2, change of +1; resulting frequency 3.
|
Current frequency 2, change of +1; resulting frequency 3.
|
||||||
In this example, the resulting frequency is 3.
|
In this example, the resulting frequency is 3.
|
||||||
|
|
||||||
Here are other example situations:
|
Here are other example situations:
|
||||||
|
|
||||||
+1, +1, +1 results in 3
|
+1, +1, +1 results in 3
|
||||||
+1, +1, -2 results in 0
|
+1, +1, -2 results in 0
|
||||||
-1, -2, -3 results in -6
|
-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?
|
Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied?
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
let input = fs.readFileSync('input.txt').toString().split('\n').join('');
|
let input = fs.readFileSync('input.txt').toString().split('\n').join('');
|
||||||
console.log(eval(input));
|
console.log(eval(input));
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,21 @@
|
|||||||
--- Part Two ---
|
--- 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.
|
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:
|
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 0, change of +1; resulting frequency 1.
|
||||||
Current frequency 1, change of -2; resulting frequency -1.
|
Current frequency 1, change of -2; resulting frequency -1.
|
||||||
Current frequency -1, change of +3; resulting frequency 2.
|
Current frequency -1, change of +3; resulting frequency 2.
|
||||||
Current frequency 2, change of +1; resulting frequency 3.
|
Current frequency 2, change of +1; resulting frequency 3.
|
||||||
(At this point, the device continues from the start of the list.)
|
(At this point, the device continues from the start of the list.)
|
||||||
Current frequency 3, change of +1; resulting frequency 4.
|
Current frequency 3, change of +1; resulting frequency 4.
|
||||||
Current frequency 4, change of -2; resulting frequency 2, which has already been seen.
|
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.
|
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:
|
Here are other examples:
|
||||||
|
|
||||||
+1, -1 first reaches 0 twice.
|
+1, -1 first reaches 0 twice.
|
||||||
+3, +3, +4, -2, -4 first reaches 10 twice.
|
+3, +3, +4, -2, -4 first reaches 10 twice.
|
||||||
-6, +3, +8, +5, -6 first reaches 5 twice.
|
-6, +3, +8, +5, -6 first reaches 5 twice.
|
||||||
+7, +7, -2, -7, -4 first reaches 14 twice.
|
+7, +7, -2, -7, -4 first reaches 14 twice.
|
||||||
What is the first frequency your device reaches twice?
|
What is the first frequency your device reaches twice?
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
let input = fs.readFileSync('input.txt')
|
let input = fs.readFileSync('input.txt')
|
||||||
.toString()
|
.toString()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((x) => parseInt(x));
|
.map((x) => parseInt(x));
|
||||||
|
|
||||||
let seenFrequencies = new Set([0]);
|
let seenFrequencies = new Set([0]);
|
||||||
let total = 0;
|
let total = 0;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (i === input.length) {
|
if (i === input.length) {
|
||||||
i = 0;
|
i = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
total += input[i];
|
total += input[i];
|
||||||
if (seenFrequencies.has(total)) {
|
if (seenFrequencies.has(total)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
seenFrequencies.add(total);
|
seenFrequencies.add(total);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(total)
|
console.log(total)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,23 @@
|
|||||||
--- Day 2: Inventory Management System ---
|
--- 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.
|
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!"
|
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.
|
"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).
|
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.
|
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:
|
For example, if you see the following box IDs:
|
||||||
|
|
||||||
abcdef contains no letters that appear exactly two or three times.
|
abcdef contains no letters that appear exactly two or three times.
|
||||||
bababc contains two a and three b, so it counts for both.
|
bababc contains two a and three b, so it counts for both.
|
||||||
abbcde contains two b, but no letter appears exactly three times.
|
abbcde contains two b, but no letter appears exactly three times.
|
||||||
abcccd contains three c, but no letter appears exactly two times.
|
abcccd contains three c, but no letter appears exactly two times.
|
||||||
aabcdd contains two a and two d, but it only counts once.
|
aabcdd contains two a and two d, but it only counts once.
|
||||||
abcdee contains two e.
|
abcdee contains two e.
|
||||||
ababab contains three a and three b, but it only counts once.
|
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.
|
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?
|
What is the checksum for your list of box IDs?
|
||||||
@@ -1,250 +1,250 @@
|
|||||||
ybruvapdgixszyckwtfqjonsie
|
ybruvapdgixszyckwtfqjonsie
|
||||||
mbruvapxghslyyckwtfqjonsie
|
mbruvapxghslyyckwtfqjonsie
|
||||||
mbruvapdghslzyckwtkujonsie
|
mbruvapdghslzyckwtkujonsie
|
||||||
rwruvapdghxlzyckwtfqjcnsie
|
rwruvapdghxlzyckwtfqjcnsie
|
||||||
obruvapdgtxlzyckwtfqionsie
|
obruvapdgtxlzyckwtfqionsie
|
||||||
lbruvapdghxqzyckwtfqjfnsie
|
lbruvapdghxqzyckwtfqjfnsie
|
||||||
mbrunapdghxlzyccatfqjonsie
|
mbrunapdghxlzyccatfqjonsie
|
||||||
mbruvapdghxlzyokltfqjdnsie
|
mbruvapdghxlzyokltfqjdnsie
|
||||||
ybruvapdghxlzmckwtfqjmnsie
|
ybruvapdghxlzmckwtfqjmnsie
|
||||||
mbruwaadghxdzyckwtfqjonsie
|
mbruwaadghxdzyckwtfqjonsie
|
||||||
muruvapdghxlzyckvtfqjonsim
|
muruvapdghxlzyckvtfqjonsim
|
||||||
mbruvapdghxlkyckwtxqjonjie
|
mbruvapdghxlkyckwtxqjonjie
|
||||||
mbruvaqdghxlzyckwtfqjrnnie
|
mbruvaqdghxlzyckwtfqjrnnie
|
||||||
mwruvapdghdlzyckttfqjonsie
|
mwruvapdghdlzyckttfqjonsie
|
||||||
mbruvapdgtelzyckwxfqjonsie
|
mbruvapdgtelzyckwxfqjonsie
|
||||||
mbruvapdohxlzvckwtfqjonhie
|
mbruvapdohxlzvckwtfqjonhie
|
||||||
mbrugapdgbxlzyckwtfqjynsie
|
mbrugapdgbxlzyckwtfqjynsie
|
||||||
mbruvapdghxlzyckwtlqjonjiu
|
mbruvapdghxlzyckwtlqjonjiu
|
||||||
mbruvapwghxlzyckwafqjonbie
|
mbruvapwghxlzyckwafqjonbie
|
||||||
wbruvapdghxlhyckwtfqjonsii
|
wbruvapdghxlhyckwtfqjonsii
|
||||||
mbruvapdghxlzyckwtcqnonsiq
|
mbruvapdghxlzyckwtcqnonsiq
|
||||||
mbyuvapighxlzybkwtfqjonsie
|
mbyuvapighxlzybkwtfqjonsie
|
||||||
mbrrvapdghxvzyckwtfqjonsio
|
mbrrvapdghxvzyckwtfqjonsio
|
||||||
mhruvapdghrlzyckwtfzjonsie
|
mhruvapdghrlzyckwtfzjonsie
|
||||||
mtruvapvghxlzyckwtfnjonsie
|
mtruvapvghxlzyckwtfnjonsie
|
||||||
mmrlhapdghxlzyckwtfqjonsie
|
mmrlhapdghxlzyckwtfqjonsie
|
||||||
mbruvapdgpxlzyjkwtfqjovsie
|
mbruvapdgpxlzyjkwtfqjovsie
|
||||||
mbrucapdghxlzymkwtzqjonsie
|
mbrucapdghxlzymkwtzqjonsie
|
||||||
mbeuvafdghxlzyckwtfqjonwie
|
mbeuvafdghxlzyckwtfqjonwie
|
||||||
mbruvapcghxlayckwtfqjonsii
|
mbruvapcghxlayckwtfqjonsii
|
||||||
mbruvabdghxlzyckwtfqyansie
|
mbruvabdghxlzyckwtfqyansie
|
||||||
mbruvjpdghxlzyckwtfqgfnsie
|
mbruvjpdghxlzyckwtfqgfnsie
|
||||||
lbruvapdghxlzyckwtfqjonriv
|
lbruvapdghxlzyckwtfqjonriv
|
||||||
mbrupapdghxlzycjwtfqronsie
|
mbrupapdghxlzycjwtfqronsie
|
||||||
mbpuvapdthxlzymkwtfqjonsie
|
mbpuvapdthxlzymkwtfqjonsie
|
||||||
mbiuvapdgixlzyckwxfqjonsie
|
mbiuvapdgixlzyckwxfqjonsie
|
||||||
mbruvapdghxyzyckwtfcjonsbe
|
mbruvapdghxyzyckwtfcjonsbe
|
||||||
mbrurapkghxlzyckwtfqjonzie
|
mbrurapkghxlzyckwtfqjonzie
|
||||||
mbrufapdrhxlzyciwtfqjonsie
|
mbrufapdrhxlzyciwtfqjonsie
|
||||||
mbruvapdghxlzbckwtfqjoisae
|
mbruvapdghxlzbckwtfqjoisae
|
||||||
ubruhapdghxlzuckwtfqjonsie
|
ubruhapdghxlzuckwtfqjonsie
|
||||||
mbruvapdjhulzyckwtfqjonshe
|
mbruvapdjhulzyckwtfqjonshe
|
||||||
mbruwapdgyxlzyckntfqjonsie
|
mbruwapdgyxlzyckntfqjonsie
|
||||||
mwruvapdghplzyckwtfqjonsme
|
mwruvapdghplzyckwtfqjonsme
|
||||||
mbruvapjghtlzyckwtfqgonsie
|
mbruvapjghtlzyckwtfqgonsie
|
||||||
pbruvapdghhlzyckwtfrjonsie
|
pbruvapdghhlzyckwtfrjonsie
|
||||||
mbruvgpdihxqzyckwtfqjonsie
|
mbruvgpdihxqzyckwtfqjonsie
|
||||||
mbruvahdohxlzyckwtfijonsie
|
mbruvahdohxlzyckwtfijonsie
|
||||||
ibuuvapdghxlzyckwtfqjofsie
|
ibuuvapdghxlzyckwtfqjofsie
|
||||||
mbruvandghxlzyckwtfqjrnxie
|
mbruvandghxlzyckwtfqjrnxie
|
||||||
mbrjvlpdghxlzyckwgfqjonsie
|
mbrjvlpdghxlzyckwgfqjonsie
|
||||||
mbruvapogfxlzyckotfqjonsie
|
mbruvapogfxlzyckotfqjonsie
|
||||||
mbruvrpdghxlzyckutfejonsie
|
mbruvrpdghxlzyckutfejonsie
|
||||||
mbruvbpdghxlzyhkwtfqjonsip
|
mbruvbpdghxlzyhkwtfqjonsip
|
||||||
mbruvapdghxlzyckmnfqjensie
|
mbruvapdghxlzyckmnfqjensie
|
||||||
mbruvapdghvlzyckwtfqjowsix
|
mbruvapdghvlzyckwtfqjowsix
|
||||||
mbruvakdgholzwckwtfqjonsie
|
mbruvakdgholzwckwtfqjonsie
|
||||||
mbruvapdghxlzackwtfqconsae
|
mbruvapdghxlzackwtfqconsae
|
||||||
mbruvapdghxlzyqvwtfqjlnsie
|
mbruvapdghxlzyqvwtfqjlnsie
|
||||||
mprrvapdgfxlzyckwtfqjonsie
|
mprrvapdgfxlzyckwtfqjonsie
|
||||||
mbrunacdghxlhyckwtfqjonsie
|
mbrunacdghxlhyckwtfqjonsie
|
||||||
obruvapdgsxlzyckwtfqjonvie
|
obruvapdgsxlzyckwtfqjonvie
|
||||||
murcvapdghslzyckwtfqjonsie
|
murcvapdghslzyckwtfqjonsie
|
||||||
mbruvapdghxlzyzkwmftjonsie
|
mbruvapdghxlzyzkwmftjonsie
|
||||||
mbrwvapdgtvlzyckwtfqjonsie
|
mbrwvapdgtvlzyckwtfqjonsie
|
||||||
mbxuvapdghxlzqcnwtfqjonsie
|
mbxuvapdghxlzqcnwtfqjonsie
|
||||||
mbruvaddghxboyckwtfqjonsie
|
mbruvaddghxboyckwtfqjonsie
|
||||||
mhruvwndghxlzyckwtfqjonsie
|
mhruvwndghxlzyckwtfqjonsie
|
||||||
mbrdvapdghxlzyckwmpqjonsie
|
mbrdvapdghxlzyckwmpqjonsie
|
||||||
mbruvapdgyxlzyckizfqjonsie
|
mbruvapdgyxlzyckizfqjonsie
|
||||||
mbruvapdghxlzlckwtfqeowsie
|
mbruvapdghxlzlckwtfqeowsie
|
||||||
mbruvbpdgrxlzyckwtfqjonsxe
|
mbruvbpdgrxlzyckwtfqjonsxe
|
||||||
mbruqapoghxlzyckwtvqjonsie
|
mbruqapoghxlzyckwtvqjonsie
|
||||||
mbouhapdghmlzyckwtfqjonsie
|
mbouhapdghmlzyckwtfqjonsie
|
||||||
mbruvapjghxidyckwtfqjonsie
|
mbruvapjghxidyckwtfqjonsie
|
||||||
mbsuvapkghxlkyckwtfqjonsie
|
mbsuvapkghxlkyckwtfqjonsie
|
||||||
mbruvlpdghxlzycrwtfqjonsis
|
mbruvlpdghxlzycrwtfqjonsis
|
||||||
mcrueapdghxlzyckwtfqjynsie
|
mcrueapdghxlzyckwtfqjynsie
|
||||||
muruvapngbxlzyckwtfqjonsie
|
muruvapngbxlzyckwtfqjonsie
|
||||||
mbruvapdghxlzycawtfyjojsie
|
mbruvapdghxlzycawtfyjojsie
|
||||||
mbruvbpdghxczyjkwtfqjonsie
|
mbruvbpdghxczyjkwtfqjonsie
|
||||||
ybduvapdghxnzyckwtfqjonsie
|
ybduvapdghxnzyckwtfqjonsie
|
||||||
mbruvbpdghxlzyckwtfbjousie
|
mbruvbpdghxlzyckwtfbjousie
|
||||||
mbouvapdghxlzycbwtfqponsie
|
mbouvapdghxlzycbwtfqponsie
|
||||||
mbruvaedghplzycgwtfqjonsie
|
mbruvaedghplzycgwtfqjonsie
|
||||||
mbrhvapdghxlzyckytfqjgnsie
|
mbrhvapdghxlzyckytfqjgnsie
|
||||||
mbruvapdqbxleyckwtfqjonsie
|
mbruvapdqbxleyckwtfqjonsie
|
||||||
mbruvapddhhldyckwtfqjonsie
|
mbruvapddhhldyckwtfqjonsie
|
||||||
mbruvapdghxlwrckwtfqjondie
|
mbruvapdghxlwrckwtfqjondie
|
||||||
mbruvapdmhxlzyckwtfqkonsve
|
mbruvapdmhxlzyckwtfqkonsve
|
||||||
xbbuvapdghxlzyckwtfkjonsie
|
xbbuvapdghxlzyckwtfkjonsie
|
||||||
mbruvapdghxlzyckwcfqjunkie
|
mbruvapdghxlzyckwcfqjunkie
|
||||||
mbruvapdghxlzyckwtfqxonfib
|
mbruvapdghxlzyckwtfqxonfib
|
||||||
mbrtvapkghxlzyckwtfqeonsie
|
mbrtvapkghxlzyckwtfqeonsie
|
||||||
mbruvazdghxldymkwtfqjonsie
|
mbruvazdghxldymkwtfqjonsie
|
||||||
kbruvapddhxlzfckwtfqjonsie
|
kbruvapddhxlzfckwtfqjonsie
|
||||||
mbouvapdghxlpyckwtfqjoosie
|
mbouvapdghxlpyckwtfqjoosie
|
||||||
mbauvapdghxlzyckwtfqjszsie
|
mbauvapdghxlzyckwtfqjszsie
|
||||||
mbruvapdghtlzyckntfqtonsie
|
mbruvapdghtlzyckntfqtonsie
|
||||||
mbruvipdggxlzbckwtfqjonsie
|
mbruvipdggxlzbckwtfqjonsie
|
||||||
mbruqapdghrlzyckwtfqjznsie
|
mbruqapdghrlzyckwtfqjznsie
|
||||||
myruvacdghxlzyckwifqjonsie
|
myruvacdghxlzyckwifqjonsie
|
||||||
mbruvapdghxlzuckwtfkjocsie
|
mbruvapdghxlzuckwtfkjocsie
|
||||||
mwjuvapdghxlzyckwtfqjonsxe
|
mwjuvapdghxlzyckwtfqjonsxe
|
||||||
mbruvapxghxlzickwtfqjobsie
|
mbruvapxghxlzickwtfqjobsie
|
||||||
mbrupapdghxtlyckwtfqjonsie
|
mbrupapdghxtlyckwtfqjonsie
|
||||||
meruvapdjjxlzyckwtfqjonsie
|
meruvapdjjxlzyckwtfqjonsie
|
||||||
mbruvkodghxlzyckwofqjonsie
|
mbruvkodghxlzyckwofqjonsie
|
||||||
mbruvapdgexlzyckwtgkjonsie
|
mbruvapdgexlzyckwtgkjonsie
|
||||||
mbruvapwghxlzyckwtcqjonsiw
|
mbruvapwghxlzyckwtcqjonsiw
|
||||||
mbruvapdghxlzykkwtfqtoxsie
|
mbruvapdghxlzykkwtfqtoxsie
|
||||||
mbruvapdahxlzycgwtfwjonsie
|
mbruvapdahxlzycgwtfwjonsie
|
||||||
mbruvapdgwxlhyckhtfqjonsie
|
mbruvapdgwxlhyckhtfqjonsie
|
||||||
mbruvapbghxlzycbhmfqjonsie
|
mbruvapbghxlzycbhmfqjonsie
|
||||||
mbruvapdghxvzyzkwtfqjonsin
|
mbruvapdghxvzyzkwtfqjonsin
|
||||||
mbrcvapdqhxlzyckwyfqjonsie
|
mbrcvapdqhxlzyckwyfqjonsie
|
||||||
zbruvaxdghxlzyckwgfqjonsie
|
zbruvaxdghxlzyckwgfqjonsie
|
||||||
mtruvapdghxlilckwtfqjonsie
|
mtruvapdghxlilckwtfqjonsie
|
||||||
bbruvapdghxlzyckwtfmjonsxe
|
bbruvapdghxlzyckwtfmjonsxe
|
||||||
mbruvajdghxlzyckwtfqfwnsie
|
mbruvajdghxlzyckwtfqfwnsie
|
||||||
mbruvapdgkxlzyckwtfqionpie
|
mbruvapdgkxlzyckwtfqionpie
|
||||||
rbruvapdghxlryckwdfqjonsie
|
rbruvapdghxlryckwdfqjonsie
|
||||||
mbruvandghxlzyckwmfvjonsie
|
mbruvandghxlzyckwmfvjonsie
|
||||||
mbruvahdghxlzeckwtfqjonsme
|
mbruvahdghxlzeckwtfqjonsme
|
||||||
mbruvnpcghxlzyckwtfqjobsie
|
mbruvnpcghxlzyckwtfqjobsie
|
||||||
mbruvapdghqlzyckwtfbjonsiy
|
mbruvapdghqlzyckwtfbjonsiy
|
||||||
mbruvavdghxlzyckwufqjodsie
|
mbruvavdghxlzyckwufqjodsie
|
||||||
mbruvapdghxlzyckwtfzmovsie
|
mbruvapdghxlzyckwtfzmovsie
|
||||||
mbruvlpdghxuzyckwtfqjoesie
|
mbruvlpdghxuzyckwtfqjoesie
|
||||||
mbruvopdghxlzycwwtfqjansie
|
mbruvopdghxlzycwwtfqjansie
|
||||||
obruvapdghglzybkwtfqjonsie
|
obruvapdghglzybkwtfqjonsie
|
||||||
mbpuvlpdghxlcyckwtfqjonsie
|
mbpuvlpdghxlcyckwtfqjonsie
|
||||||
mbruvaidghxlzyckwtfmjonoie
|
mbruvaidghxlzyckwtfmjonoie
|
||||||
mbruvapdihxzzyckwtfqjonsiy
|
mbruvapdihxzzyckwtfqjonsiy
|
||||||
mbquvapdghxlzyckwtfqconsme
|
mbquvapdghxlzyckwtfqconsme
|
||||||
mbruvapdghslzyckqtfqjojsie
|
mbruvapdghslzyckqtfqjojsie
|
||||||
mbrzdapdghxmzyckwtfqjonsie
|
mbrzdapdghxmzyckwtfqjonsie
|
||||||
mwruvapdghxozyckwtfqjonsxe
|
mwruvapdghxozyckwtfqjonsxe
|
||||||
muruvapdgfxlzyckwtfqjojsie
|
muruvapdgfxlzyckwtfqjojsie
|
||||||
wtruvapdghxlzyckvtfqjonsie
|
wtruvapdghxlzyckvtfqjonsie
|
||||||
mbruvapdghxlzyckysfqjxnsie
|
mbruvapdghxlzyckysfqjxnsie
|
||||||
mbruvrpdghxczyckktfqjonsie
|
mbruvrpdghxczyckktfqjonsie
|
||||||
mbquvapdghxlryckwtfqjonsne
|
mbquvapdghxlryckwtfqjonsne
|
||||||
mbruvapdghflzycvwtfqjpnsie
|
mbruvapdghflzycvwtfqjpnsie
|
||||||
mbruvapughclzyckwtfqjonsin
|
mbruvapughclzyckwtfqjonsin
|
||||||
mbrhvapdghxlpyckwtfqjonsre
|
mbrhvapdghxlpyckwtfqjonsre
|
||||||
mbruvapdgtxlzyckwtfqjoosit
|
mbruvapdgtxlzyckwtfqjoosit
|
||||||
mbrupapnghxhzyckwtfqjonsie
|
mbrupapnghxhzyckwtfqjonsie
|
||||||
mmvuvapdvhxlzyckwtfqjonsie
|
mmvuvapdvhxlzyckwtfqjonsie
|
||||||
mbruvaptghxlzyckwtfqjotsse
|
mbruvaptghxlzyckwtfqjotsse
|
||||||
mgruvapvghxlzyckwtfqjonsix
|
mgruvapvghxlzyckwtfqjonsix
|
||||||
mbrupapdghxszyckwtfqjunsie
|
mbrupapdghxszyckwtfqjunsie
|
||||||
mbruvkpdghelzyckwtfqjpnsie
|
mbruvkpdghelzyckwtfqjpnsie
|
||||||
mbruvrrdghjlzyckwtfqjonsie
|
mbruvrrdghjlzyckwtfqjonsie
|
||||||
mbruvapdghnlzyckwtfkjonsze
|
mbruvapdghnlzyckwtfkjonsze
|
||||||
mbruvwpdghxlzyckwtfqhoysie
|
mbruvwpdghxlzyckwtfqhoysie
|
||||||
mbrsvapdfhxlzyckwtfqjobsie
|
mbrsvapdfhxlzyckwtfqjobsie
|
||||||
mbruvapdgexezymkwtfqjonsie
|
mbruvapdgexezymkwtfqjonsie
|
||||||
ybruvapdghxlzyckwtfqxonsiw
|
ybruvapdghxlzyckwtfqxonsiw
|
||||||
mrruvapdghxdzyckwtfqjossie
|
mrruvapdghxdzyckwtfqjossie
|
||||||
mbruvapdghtlzyckwtfqconsiu
|
mbruvapdghtlzyckwtfqconsiu
|
||||||
mbrpvapdghxlzlckwpfqjonsie
|
mbrpvapdghxlzlckwpfqjonsie
|
||||||
mbruvjpdghslzyckwtfqjjnsie
|
mbruvjpdghslzyckwtfqjjnsie
|
||||||
mhruvapoghxlzyckwtfvjonsie
|
mhruvapoghxlzyckwtfvjonsie
|
||||||
mbrubqpdghvlzyckwtfqjonsie
|
mbrubqpdghvlzyckwtfqjonsie
|
||||||
mbruvapdghxlzackwtfqconsiw
|
mbruvapdghxlzackwtfqconsiw
|
||||||
mbruvapdgnxlzkckwtfqjdnsie
|
mbruvapdgnxlzkckwtfqjdnsie
|
||||||
mbrudapgghelzyckwtfqjonsie
|
mbrudapgghelzyckwtfqjonsie
|
||||||
mbruvapdghxlzlakwbfqjonsie
|
mbruvapdghxlzlakwbfqjonsie
|
||||||
mbpuvapdghxlzyckwtuqjonjie
|
mbpuvapdghxlzyckwtuqjonjie
|
||||||
abruvapdghxlzykkwtfqjonzie
|
abruvapdghxlzykkwtfqjonzie
|
||||||
mbrupupdghxlsyckwtfqjonsie
|
mbrupupdghxlsyckwtfqjonsie
|
||||||
mbrsvupdghxlzyckwtfqjonkie
|
mbrsvupdghxlzyckwtfqjonkie
|
||||||
mxruvgpdghxllyckwtfqjonsie
|
mxruvgpdghxllyckwtfqjonsie
|
||||||
mbrnvapdghxlzycbwtfqfonsie
|
mbrnvapdghxlzycbwtfqfonsie
|
||||||
mbrbxapdghxlzyckttfqjonsie
|
mbrbxapdghxlzyckttfqjonsie
|
||||||
mbnuvapdghxlzyxkwtmqjonsie
|
mbnuvapdghxlzyxkwtmqjonsie
|
||||||
mbrfvapdghjlzickwtfqjonsie
|
mbrfvapdghjlzickwtfqjonsie
|
||||||
mbhuvupdghxlzyxkwtfqjonsie
|
mbhuvupdghxlzyxkwtfqjonsie
|
||||||
mbrcvapdghxluyckwtfqjznsie
|
mbrcvapdghxluyckwtfqjznsie
|
||||||
mbruvapdghxlzyckwofqjoxsiz
|
mbruvapdghxlzyckwofqjoxsiz
|
||||||
mbrevapdghxloyckwtfqjonnie
|
mbrevapdghxloyckwtfqjonnie
|
||||||
mbruvipdghnlzyckwtfqjopsie
|
mbruvipdghnlzyckwtfqjopsie
|
||||||
mbxxvaptghxlzyckwtfqjonsie
|
mbxxvaptghxlzyckwtfqjonsie
|
||||||
mbruvcpdghxlztckwtjqjonsie
|
mbruvcpdghxlztckwtjqjonsie
|
||||||
mqruvlpdghxlzyckotfqjonsie
|
mqruvlpdghxlzyckotfqjonsie
|
||||||
mbruvapdgqxlzyckwtfqjpvsie
|
mbruvapdgqxlzyckwtfqjpvsie
|
||||||
mbruvapdgvxlzyjkwtfqjbnsie
|
mbruvapdgvxlzyjkwtfqjbnsie
|
||||||
mbruvapdghxlgyckwtfqcocsie
|
mbruvapdghxlgyckwtfqcocsie
|
||||||
mbruvapdghxkwyckwtfqjoqsie
|
mbruvapdghxkwyckwtfqjoqsie
|
||||||
mbrgvavdghxlzyckwxfqjonsie
|
mbrgvavdghxlzyckwxfqjonsie
|
||||||
qbruqapdgvxlzyckwtfqjonsie
|
qbruqapdgvxlzyckwtfqjonsie
|
||||||
mbauvapdghxlzgckwtfqjunsie
|
mbauvapdghxlzgckwtfqjunsie
|
||||||
mbruvapdgdxluyckwtfqjoosie
|
mbruvapdgdxluyckwtfqjoosie
|
||||||
mbruvapdghxlzykkwtfqwobsie
|
mbruvapdghxlzykkwtfqwobsie
|
||||||
mbruvapdghxlzhcnwtfqjonqie
|
mbruvapdghxlzhcnwtfqjonqie
|
||||||
mbruvapdghxlzycbhmfqjonsie
|
mbruvapdghxlzycbhmfqjonsie
|
||||||
mbruvapdghxluyczwtfqjontie
|
mbruvapdghxluyczwtfqjontie
|
||||||
mbruvapnghxlzyckwnfqjonbie
|
mbruvapnghxlzyckwnfqjonbie
|
||||||
moruvapdghxlzcckwtfqponsie
|
moruvapdghxlzcckwtfqponsie
|
||||||
mbruvapfgxxlzyckwtfqjunsie
|
mbruvapfgxxlzyckwtfqjunsie
|
||||||
mbruvapdghxlryckvtfejonsie
|
mbruvapdghxlryckvtfejonsie
|
||||||
mbrzvapdghxlzvcbwtfqjonsie
|
mbrzvapdghxlzvcbwtfqjonsie
|
||||||
mbruvapdgqxlzyckwcfqjonsce
|
mbruvapdgqxlzyckwcfqjonsce
|
||||||
abruvupdrhxlzyckwtfqjonsie
|
abruvupdrhxlzyckwtfqjonsie
|
||||||
mbrubaptghxlzyckwtfqjondie
|
mbrubaptghxlzyckwtfqjondie
|
||||||
mgruvapdgpxlzyckwtfijonsie
|
mgruvapdgpxlzyckwtfijonsie
|
||||||
mbruvapdghxczlckwtfujonsie
|
mbruvapdghxczlckwtfujonsie
|
||||||
mbruvapdgmmlzyckwtfqjonsir
|
mbruvapdgmmlzyckwtfqjonsir
|
||||||
mbruvapdhhxltyckwtfdjonsie
|
mbruvapdhhxltyckwtfdjonsie
|
||||||
mbruvapdghxlzyckwtfdjjnste
|
mbruvapdghxlzyckwtfdjjnste
|
||||||
mbrdvzpdghxlcyckwtfqjonsie
|
mbrdvzpdghxlcyckwtfqjonsie
|
||||||
mbruvapdghxlzyckwtnqbonsim
|
mbruvapdghxlzyckwtnqbonsim
|
||||||
mbrovapdghxlzyckwtfpjousie
|
mbrovapdghxlzyckwtfpjousie
|
||||||
mymuvapdghxlzyjkwtfqjonsie
|
mymuvapdghxlzyjkwtfqjonsie
|
||||||
mbpuvapdghxlzyckwtfljcnsie
|
mbpuvapdghxlzyckwtfljcnsie
|
||||||
mbrxvapdghxlzyclwtfqjonpie
|
mbrxvapdghxlzyclwtfqjonpie
|
||||||
mbrueapdghxlzyckwtfqjopsia
|
mbrueapdghxlzyckwtfqjopsia
|
||||||
mbruvapdghxlzycdwtfqjbfsie
|
mbruvapdghxlzycdwtfqjbfsie
|
||||||
tbruvavdghxlzyckwtmqjonsie
|
tbruvavdghxlzyckwtmqjonsie
|
||||||
mbduvapdghxlzyckwrfqjrnsie
|
mbduvapdghxlzyckwrfqjrnsie
|
||||||
mkrsvapughxlzyckwtfqjonsie
|
mkrsvapughxlzyckwtfqjonsie
|
||||||
mbruvapdghylzyckwtfqtolsie
|
mbruvapdghylzyckwtfqtolsie
|
||||||
mgruvapdglxldyckwtfqjonsie
|
mgruvapdglxldyckwtfqjonsie
|
||||||
mbrunapdghclzyckwtfqjonsiy
|
mbrunapdghclzyckwtfqjonsiy
|
||||||
mbruvapdgrxlxyckwtfgjonsie
|
mbruvapdgrxlxyckwtfgjonsie
|
||||||
mbruvapdghxpzbckftfqjonsie
|
mbruvapdghxpzbckftfqjonsie
|
||||||
mbruvcpdghxyzyckotfqjonsie
|
mbruvcpdghxyzyckotfqjonsie
|
||||||
mbruvapdghxlsyckwtfqcqnsie
|
mbruvapdghxlsyckwtfqcqnsie
|
||||||
mbruvapdghxlzzckwtfqjonskf
|
mbruvapdghxlzzckwtfqjonskf
|
||||||
mbruvppdghxlzfckwtfqjgnsie
|
mbruvppdghxlzfckwtfqjgnsie
|
||||||
mbhuvapdghxlzytkwtfqjonoie
|
mbhuvapdghxlzytkwtfqjonoie
|
||||||
mbruvapdghxlzvrkwtfqjjnsie
|
mbruvapdghxlzvrkwtfqjjnsie
|
||||||
mbmuvapdghxuzyckwtfqjonsze
|
mbmuvapdghxuzyckwtfqjonsze
|
||||||
mbruvapdghnlzycnwtfqjonsil
|
mbruvapdghnlzycnwtfqjonsil
|
||||||
mbruvapdgholzyckitfqjonsia
|
mbruvapdgholzyckitfqjonsia
|
||||||
mbruxapdghxlmyckwtfqbonsie
|
mbruxapdghxlmyckwtfqbonsie
|
||||||
mbauvapdgholzyckwtfqjolsie
|
mbauvapdgholzyckwtfqjolsie
|
||||||
mbruvapdghxlzyckwtfqjotslq
|
mbruvapdghxlzyckwtfqjotslq
|
||||||
dbrutapdghxlzyckwtfqjonsiv
|
dbrutapdghxlzyckwtfqjonsiv
|
||||||
mbruvapdzhxlyyckwtfbjonsie
|
mbruvapdzhxlyyckwtfbjonsie
|
||||||
mmruaapsghxlzyckwtfqjonsie
|
mmruaapsghxlzyckwtfqjonsie
|
||||||
mbruvaldgqxqzyckwtfqjonsie
|
mbruvaldgqxqzyckwtfqjonsie
|
||||||
mbruvaodghxdzyjkwtfqjonsie
|
mbruvaodghxdzyjkwtfqjonsie
|
||||||
mbrcmatdghxlzyckwtfqjonsie
|
mbrcmatdghxlzyckwtfqjonsie
|
||||||
mbrqvapdgtxlzycewtfqjonsie
|
mbrqvapdgtxlzycewtfqjonsie
|
||||||
mjruvapdghzlzyckwtfqjonrie
|
mjruvapdghzlzyckwtfqjonrie
|
||||||
mbruvapdghxopcckwtfqjonsie
|
mbruvapdghxopcckwtfqjonsie
|
||||||
mbruvapdghxszycwwtfqjoqsie
|
mbruvapdghxszycwwtfqjoqsie
|
||||||
mbruvapdgoxezyckwtjqjonsie
|
mbruvapdgoxezyckwtjqjonsie
|
||||||
@@ -1,36 +1,36 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
bool isRepeat(std::string line, int repeats) {
|
bool isRepeat(std::string line, int repeats) {
|
||||||
for (char c = 'a'; c <= 'z'; ++c) {
|
for (char c = 'a'; c <= 'z'; ++c) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (size_t i = 0; i < line.size(); ++i) {
|
for (size_t i = 0; i < line.size(); ++i) {
|
||||||
if (line[i] == c)
|
if (line[i] == c)
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
if (count == repeats)
|
if (count == repeats)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkSum(std::string fileName) {
|
int checkSum(std::string fileName) {
|
||||||
std::fstream input(fileName);
|
std::fstream input(fileName);
|
||||||
std::string line;
|
std::string line;
|
||||||
int doubles = 0;
|
int doubles = 0;
|
||||||
int triples = 0;
|
int triples = 0;
|
||||||
|
|
||||||
while (!input.eof()) {
|
while (!input.eof()) {
|
||||||
std::getline(input, line);
|
std::getline(input, line);
|
||||||
if (isRepeat(line, 2))
|
if (isRepeat(line, 2))
|
||||||
++doubles;
|
++doubles;
|
||||||
if (isRepeat(line, 3))
|
if (isRepeat(line, 3))
|
||||||
++triples;
|
++triples;
|
||||||
}
|
}
|
||||||
return doubles * triples;
|
return doubles * triples;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
std::cout << "Found: " << checkSum("input.txt") << std::endl;
|
std::cout << "Found: " << checkSum("input.txt") << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
Confident that your list of box IDs is complete, you're ready to find the boxes full of prototype fabric.
|
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:
|
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
|
abcde
|
||||||
fghij
|
fghij
|
||||||
klmno
|
klmno
|
||||||
pqrst
|
pqrst
|
||||||
fguij
|
fguij
|
||||||
axcye
|
axcye
|
||||||
wvxyz
|
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.
|
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.)
|
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.)
|
||||||
@@ -1,250 +1,250 @@
|
|||||||
ybruvapdgixszyckwtfqjonsie
|
ybruvapdgixszyckwtfqjonsie
|
||||||
mbruvapxghslyyckwtfqjonsie
|
mbruvapxghslyyckwtfqjonsie
|
||||||
mbruvapdghslzyckwtkujonsie
|
mbruvapdghslzyckwtkujonsie
|
||||||
rwruvapdghxlzyckwtfqjcnsie
|
rwruvapdghxlzyckwtfqjcnsie
|
||||||
obruvapdgtxlzyckwtfqionsie
|
obruvapdgtxlzyckwtfqionsie
|
||||||
lbruvapdghxqzyckwtfqjfnsie
|
lbruvapdghxqzyckwtfqjfnsie
|
||||||
mbrunapdghxlzyccatfqjonsie
|
mbrunapdghxlzyccatfqjonsie
|
||||||
mbruvapdghxlzyokltfqjdnsie
|
mbruvapdghxlzyokltfqjdnsie
|
||||||
ybruvapdghxlzmckwtfqjmnsie
|
ybruvapdghxlzmckwtfqjmnsie
|
||||||
mbruwaadghxdzyckwtfqjonsie
|
mbruwaadghxdzyckwtfqjonsie
|
||||||
muruvapdghxlzyckvtfqjonsim
|
muruvapdghxlzyckvtfqjonsim
|
||||||
mbruvapdghxlkyckwtxqjonjie
|
mbruvapdghxlkyckwtxqjonjie
|
||||||
mbruvaqdghxlzyckwtfqjrnnie
|
mbruvaqdghxlzyckwtfqjrnnie
|
||||||
mwruvapdghdlzyckttfqjonsie
|
mwruvapdghdlzyckttfqjonsie
|
||||||
mbruvapdgtelzyckwxfqjonsie
|
mbruvapdgtelzyckwxfqjonsie
|
||||||
mbruvapdohxlzvckwtfqjonhie
|
mbruvapdohxlzvckwtfqjonhie
|
||||||
mbrugapdgbxlzyckwtfqjynsie
|
mbrugapdgbxlzyckwtfqjynsie
|
||||||
mbruvapdghxlzyckwtlqjonjiu
|
mbruvapdghxlzyckwtlqjonjiu
|
||||||
mbruvapwghxlzyckwafqjonbie
|
mbruvapwghxlzyckwafqjonbie
|
||||||
wbruvapdghxlhyckwtfqjonsii
|
wbruvapdghxlhyckwtfqjonsii
|
||||||
mbruvapdghxlzyckwtcqnonsiq
|
mbruvapdghxlzyckwtcqnonsiq
|
||||||
mbyuvapighxlzybkwtfqjonsie
|
mbyuvapighxlzybkwtfqjonsie
|
||||||
mbrrvapdghxvzyckwtfqjonsio
|
mbrrvapdghxvzyckwtfqjonsio
|
||||||
mhruvapdghrlzyckwtfzjonsie
|
mhruvapdghrlzyckwtfzjonsie
|
||||||
mtruvapvghxlzyckwtfnjonsie
|
mtruvapvghxlzyckwtfnjonsie
|
||||||
mmrlhapdghxlzyckwtfqjonsie
|
mmrlhapdghxlzyckwtfqjonsie
|
||||||
mbruvapdgpxlzyjkwtfqjovsie
|
mbruvapdgpxlzyjkwtfqjovsie
|
||||||
mbrucapdghxlzymkwtzqjonsie
|
mbrucapdghxlzymkwtzqjonsie
|
||||||
mbeuvafdghxlzyckwtfqjonwie
|
mbeuvafdghxlzyckwtfqjonwie
|
||||||
mbruvapcghxlayckwtfqjonsii
|
mbruvapcghxlayckwtfqjonsii
|
||||||
mbruvabdghxlzyckwtfqyansie
|
mbruvabdghxlzyckwtfqyansie
|
||||||
mbruvjpdghxlzyckwtfqgfnsie
|
mbruvjpdghxlzyckwtfqgfnsie
|
||||||
lbruvapdghxlzyckwtfqjonriv
|
lbruvapdghxlzyckwtfqjonriv
|
||||||
mbrupapdghxlzycjwtfqronsie
|
mbrupapdghxlzycjwtfqronsie
|
||||||
mbpuvapdthxlzymkwtfqjonsie
|
mbpuvapdthxlzymkwtfqjonsie
|
||||||
mbiuvapdgixlzyckwxfqjonsie
|
mbiuvapdgixlzyckwxfqjonsie
|
||||||
mbruvapdghxyzyckwtfcjonsbe
|
mbruvapdghxyzyckwtfcjonsbe
|
||||||
mbrurapkghxlzyckwtfqjonzie
|
mbrurapkghxlzyckwtfqjonzie
|
||||||
mbrufapdrhxlzyciwtfqjonsie
|
mbrufapdrhxlzyciwtfqjonsie
|
||||||
mbruvapdghxlzbckwtfqjoisae
|
mbruvapdghxlzbckwtfqjoisae
|
||||||
ubruhapdghxlzuckwtfqjonsie
|
ubruhapdghxlzuckwtfqjonsie
|
||||||
mbruvapdjhulzyckwtfqjonshe
|
mbruvapdjhulzyckwtfqjonshe
|
||||||
mbruwapdgyxlzyckntfqjonsie
|
mbruwapdgyxlzyckntfqjonsie
|
||||||
mwruvapdghplzyckwtfqjonsme
|
mwruvapdghplzyckwtfqjonsme
|
||||||
mbruvapjghtlzyckwtfqgonsie
|
mbruvapjghtlzyckwtfqgonsie
|
||||||
pbruvapdghhlzyckwtfrjonsie
|
pbruvapdghhlzyckwtfrjonsie
|
||||||
mbruvgpdihxqzyckwtfqjonsie
|
mbruvgpdihxqzyckwtfqjonsie
|
||||||
mbruvahdohxlzyckwtfijonsie
|
mbruvahdohxlzyckwtfijonsie
|
||||||
ibuuvapdghxlzyckwtfqjofsie
|
ibuuvapdghxlzyckwtfqjofsie
|
||||||
mbruvandghxlzyckwtfqjrnxie
|
mbruvandghxlzyckwtfqjrnxie
|
||||||
mbrjvlpdghxlzyckwgfqjonsie
|
mbrjvlpdghxlzyckwgfqjonsie
|
||||||
mbruvapogfxlzyckotfqjonsie
|
mbruvapogfxlzyckotfqjonsie
|
||||||
mbruvrpdghxlzyckutfejonsie
|
mbruvrpdghxlzyckutfejonsie
|
||||||
mbruvbpdghxlzyhkwtfqjonsip
|
mbruvbpdghxlzyhkwtfqjonsip
|
||||||
mbruvapdghxlzyckmnfqjensie
|
mbruvapdghxlzyckmnfqjensie
|
||||||
mbruvapdghvlzyckwtfqjowsix
|
mbruvapdghvlzyckwtfqjowsix
|
||||||
mbruvakdgholzwckwtfqjonsie
|
mbruvakdgholzwckwtfqjonsie
|
||||||
mbruvapdghxlzackwtfqconsae
|
mbruvapdghxlzackwtfqconsae
|
||||||
mbruvapdghxlzyqvwtfqjlnsie
|
mbruvapdghxlzyqvwtfqjlnsie
|
||||||
mprrvapdgfxlzyckwtfqjonsie
|
mprrvapdgfxlzyckwtfqjonsie
|
||||||
mbrunacdghxlhyckwtfqjonsie
|
mbrunacdghxlhyckwtfqjonsie
|
||||||
obruvapdgsxlzyckwtfqjonvie
|
obruvapdgsxlzyckwtfqjonvie
|
||||||
murcvapdghslzyckwtfqjonsie
|
murcvapdghslzyckwtfqjonsie
|
||||||
mbruvapdghxlzyzkwmftjonsie
|
mbruvapdghxlzyzkwmftjonsie
|
||||||
mbrwvapdgtvlzyckwtfqjonsie
|
mbrwvapdgtvlzyckwtfqjonsie
|
||||||
mbxuvapdghxlzqcnwtfqjonsie
|
mbxuvapdghxlzqcnwtfqjonsie
|
||||||
mbruvaddghxboyckwtfqjonsie
|
mbruvaddghxboyckwtfqjonsie
|
||||||
mhruvwndghxlzyckwtfqjonsie
|
mhruvwndghxlzyckwtfqjonsie
|
||||||
mbrdvapdghxlzyckwmpqjonsie
|
mbrdvapdghxlzyckwmpqjonsie
|
||||||
mbruvapdgyxlzyckizfqjonsie
|
mbruvapdgyxlzyckizfqjonsie
|
||||||
mbruvapdghxlzlckwtfqeowsie
|
mbruvapdghxlzlckwtfqeowsie
|
||||||
mbruvbpdgrxlzyckwtfqjonsxe
|
mbruvbpdgrxlzyckwtfqjonsxe
|
||||||
mbruqapoghxlzyckwtvqjonsie
|
mbruqapoghxlzyckwtvqjonsie
|
||||||
mbouhapdghmlzyckwtfqjonsie
|
mbouhapdghmlzyckwtfqjonsie
|
||||||
mbruvapjghxidyckwtfqjonsie
|
mbruvapjghxidyckwtfqjonsie
|
||||||
mbsuvapkghxlkyckwtfqjonsie
|
mbsuvapkghxlkyckwtfqjonsie
|
||||||
mbruvlpdghxlzycrwtfqjonsis
|
mbruvlpdghxlzycrwtfqjonsis
|
||||||
mcrueapdghxlzyckwtfqjynsie
|
mcrueapdghxlzyckwtfqjynsie
|
||||||
muruvapngbxlzyckwtfqjonsie
|
muruvapngbxlzyckwtfqjonsie
|
||||||
mbruvapdghxlzycawtfyjojsie
|
mbruvapdghxlzycawtfyjojsie
|
||||||
mbruvbpdghxczyjkwtfqjonsie
|
mbruvbpdghxczyjkwtfqjonsie
|
||||||
ybduvapdghxnzyckwtfqjonsie
|
ybduvapdghxnzyckwtfqjonsie
|
||||||
mbruvbpdghxlzyckwtfbjousie
|
mbruvbpdghxlzyckwtfbjousie
|
||||||
mbouvapdghxlzycbwtfqponsie
|
mbouvapdghxlzycbwtfqponsie
|
||||||
mbruvaedghplzycgwtfqjonsie
|
mbruvaedghplzycgwtfqjonsie
|
||||||
mbrhvapdghxlzyckytfqjgnsie
|
mbrhvapdghxlzyckytfqjgnsie
|
||||||
mbruvapdqbxleyckwtfqjonsie
|
mbruvapdqbxleyckwtfqjonsie
|
||||||
mbruvapddhhldyckwtfqjonsie
|
mbruvapddhhldyckwtfqjonsie
|
||||||
mbruvapdghxlwrckwtfqjondie
|
mbruvapdghxlwrckwtfqjondie
|
||||||
mbruvapdmhxlzyckwtfqkonsve
|
mbruvapdmhxlzyckwtfqkonsve
|
||||||
xbbuvapdghxlzyckwtfkjonsie
|
xbbuvapdghxlzyckwtfkjonsie
|
||||||
mbruvapdghxlzyckwcfqjunkie
|
mbruvapdghxlzyckwcfqjunkie
|
||||||
mbruvapdghxlzyckwtfqxonfib
|
mbruvapdghxlzyckwtfqxonfib
|
||||||
mbrtvapkghxlzyckwtfqeonsie
|
mbrtvapkghxlzyckwtfqeonsie
|
||||||
mbruvazdghxldymkwtfqjonsie
|
mbruvazdghxldymkwtfqjonsie
|
||||||
kbruvapddhxlzfckwtfqjonsie
|
kbruvapddhxlzfckwtfqjonsie
|
||||||
mbouvapdghxlpyckwtfqjoosie
|
mbouvapdghxlpyckwtfqjoosie
|
||||||
mbauvapdghxlzyckwtfqjszsie
|
mbauvapdghxlzyckwtfqjszsie
|
||||||
mbruvapdghtlzyckntfqtonsie
|
mbruvapdghtlzyckntfqtonsie
|
||||||
mbruvipdggxlzbckwtfqjonsie
|
mbruvipdggxlzbckwtfqjonsie
|
||||||
mbruqapdghrlzyckwtfqjznsie
|
mbruqapdghrlzyckwtfqjznsie
|
||||||
myruvacdghxlzyckwifqjonsie
|
myruvacdghxlzyckwifqjonsie
|
||||||
mbruvapdghxlzuckwtfkjocsie
|
mbruvapdghxlzuckwtfkjocsie
|
||||||
mwjuvapdghxlzyckwtfqjonsxe
|
mwjuvapdghxlzyckwtfqjonsxe
|
||||||
mbruvapxghxlzickwtfqjobsie
|
mbruvapxghxlzickwtfqjobsie
|
||||||
mbrupapdghxtlyckwtfqjonsie
|
mbrupapdghxtlyckwtfqjonsie
|
||||||
meruvapdjjxlzyckwtfqjonsie
|
meruvapdjjxlzyckwtfqjonsie
|
||||||
mbruvkodghxlzyckwofqjonsie
|
mbruvkodghxlzyckwofqjonsie
|
||||||
mbruvapdgexlzyckwtgkjonsie
|
mbruvapdgexlzyckwtgkjonsie
|
||||||
mbruvapwghxlzyckwtcqjonsiw
|
mbruvapwghxlzyckwtcqjonsiw
|
||||||
mbruvapdghxlzykkwtfqtoxsie
|
mbruvapdghxlzykkwtfqtoxsie
|
||||||
mbruvapdahxlzycgwtfwjonsie
|
mbruvapdahxlzycgwtfwjonsie
|
||||||
mbruvapdgwxlhyckhtfqjonsie
|
mbruvapdgwxlhyckhtfqjonsie
|
||||||
mbruvapbghxlzycbhmfqjonsie
|
mbruvapbghxlzycbhmfqjonsie
|
||||||
mbruvapdghxvzyzkwtfqjonsin
|
mbruvapdghxvzyzkwtfqjonsin
|
||||||
mbrcvapdqhxlzyckwyfqjonsie
|
mbrcvapdqhxlzyckwyfqjonsie
|
||||||
zbruvaxdghxlzyckwgfqjonsie
|
zbruvaxdghxlzyckwgfqjonsie
|
||||||
mtruvapdghxlilckwtfqjonsie
|
mtruvapdghxlilckwtfqjonsie
|
||||||
bbruvapdghxlzyckwtfmjonsxe
|
bbruvapdghxlzyckwtfmjonsxe
|
||||||
mbruvajdghxlzyckwtfqfwnsie
|
mbruvajdghxlzyckwtfqfwnsie
|
||||||
mbruvapdgkxlzyckwtfqionpie
|
mbruvapdgkxlzyckwtfqionpie
|
||||||
rbruvapdghxlryckwdfqjonsie
|
rbruvapdghxlryckwdfqjonsie
|
||||||
mbruvandghxlzyckwmfvjonsie
|
mbruvandghxlzyckwmfvjonsie
|
||||||
mbruvahdghxlzeckwtfqjonsme
|
mbruvahdghxlzeckwtfqjonsme
|
||||||
mbruvnpcghxlzyckwtfqjobsie
|
mbruvnpcghxlzyckwtfqjobsie
|
||||||
mbruvapdghqlzyckwtfbjonsiy
|
mbruvapdghqlzyckwtfbjonsiy
|
||||||
mbruvavdghxlzyckwufqjodsie
|
mbruvavdghxlzyckwufqjodsie
|
||||||
mbruvapdghxlzyckwtfzmovsie
|
mbruvapdghxlzyckwtfzmovsie
|
||||||
mbruvlpdghxuzyckwtfqjoesie
|
mbruvlpdghxuzyckwtfqjoesie
|
||||||
mbruvopdghxlzycwwtfqjansie
|
mbruvopdghxlzycwwtfqjansie
|
||||||
obruvapdghglzybkwtfqjonsie
|
obruvapdghglzybkwtfqjonsie
|
||||||
mbpuvlpdghxlcyckwtfqjonsie
|
mbpuvlpdghxlcyckwtfqjonsie
|
||||||
mbruvaidghxlzyckwtfmjonoie
|
mbruvaidghxlzyckwtfmjonoie
|
||||||
mbruvapdihxzzyckwtfqjonsiy
|
mbruvapdihxzzyckwtfqjonsiy
|
||||||
mbquvapdghxlzyckwtfqconsme
|
mbquvapdghxlzyckwtfqconsme
|
||||||
mbruvapdghslzyckqtfqjojsie
|
mbruvapdghslzyckqtfqjojsie
|
||||||
mbrzdapdghxmzyckwtfqjonsie
|
mbrzdapdghxmzyckwtfqjonsie
|
||||||
mwruvapdghxozyckwtfqjonsxe
|
mwruvapdghxozyckwtfqjonsxe
|
||||||
muruvapdgfxlzyckwtfqjojsie
|
muruvapdgfxlzyckwtfqjojsie
|
||||||
wtruvapdghxlzyckvtfqjonsie
|
wtruvapdghxlzyckvtfqjonsie
|
||||||
mbruvapdghxlzyckysfqjxnsie
|
mbruvapdghxlzyckysfqjxnsie
|
||||||
mbruvrpdghxczyckktfqjonsie
|
mbruvrpdghxczyckktfqjonsie
|
||||||
mbquvapdghxlryckwtfqjonsne
|
mbquvapdghxlryckwtfqjonsne
|
||||||
mbruvapdghflzycvwtfqjpnsie
|
mbruvapdghflzycvwtfqjpnsie
|
||||||
mbruvapughclzyckwtfqjonsin
|
mbruvapughclzyckwtfqjonsin
|
||||||
mbrhvapdghxlpyckwtfqjonsre
|
mbrhvapdghxlpyckwtfqjonsre
|
||||||
mbruvapdgtxlzyckwtfqjoosit
|
mbruvapdgtxlzyckwtfqjoosit
|
||||||
mbrupapnghxhzyckwtfqjonsie
|
mbrupapnghxhzyckwtfqjonsie
|
||||||
mmvuvapdvhxlzyckwtfqjonsie
|
mmvuvapdvhxlzyckwtfqjonsie
|
||||||
mbruvaptghxlzyckwtfqjotsse
|
mbruvaptghxlzyckwtfqjotsse
|
||||||
mgruvapvghxlzyckwtfqjonsix
|
mgruvapvghxlzyckwtfqjonsix
|
||||||
mbrupapdghxszyckwtfqjunsie
|
mbrupapdghxszyckwtfqjunsie
|
||||||
mbruvkpdghelzyckwtfqjpnsie
|
mbruvkpdghelzyckwtfqjpnsie
|
||||||
mbruvrrdghjlzyckwtfqjonsie
|
mbruvrrdghjlzyckwtfqjonsie
|
||||||
mbruvapdghnlzyckwtfkjonsze
|
mbruvapdghnlzyckwtfkjonsze
|
||||||
mbruvwpdghxlzyckwtfqhoysie
|
mbruvwpdghxlzyckwtfqhoysie
|
||||||
mbrsvapdfhxlzyckwtfqjobsie
|
mbrsvapdfhxlzyckwtfqjobsie
|
||||||
mbruvapdgexezymkwtfqjonsie
|
mbruvapdgexezymkwtfqjonsie
|
||||||
ybruvapdghxlzyckwtfqxonsiw
|
ybruvapdghxlzyckwtfqxonsiw
|
||||||
mrruvapdghxdzyckwtfqjossie
|
mrruvapdghxdzyckwtfqjossie
|
||||||
mbruvapdghtlzyckwtfqconsiu
|
mbruvapdghtlzyckwtfqconsiu
|
||||||
mbrpvapdghxlzlckwpfqjonsie
|
mbrpvapdghxlzlckwpfqjonsie
|
||||||
mbruvjpdghslzyckwtfqjjnsie
|
mbruvjpdghslzyckwtfqjjnsie
|
||||||
mhruvapoghxlzyckwtfvjonsie
|
mhruvapoghxlzyckwtfvjonsie
|
||||||
mbrubqpdghvlzyckwtfqjonsie
|
mbrubqpdghvlzyckwtfqjonsie
|
||||||
mbruvapdghxlzackwtfqconsiw
|
mbruvapdghxlzackwtfqconsiw
|
||||||
mbruvapdgnxlzkckwtfqjdnsie
|
mbruvapdgnxlzkckwtfqjdnsie
|
||||||
mbrudapgghelzyckwtfqjonsie
|
mbrudapgghelzyckwtfqjonsie
|
||||||
mbruvapdghxlzlakwbfqjonsie
|
mbruvapdghxlzlakwbfqjonsie
|
||||||
mbpuvapdghxlzyckwtuqjonjie
|
mbpuvapdghxlzyckwtuqjonjie
|
||||||
abruvapdghxlzykkwtfqjonzie
|
abruvapdghxlzykkwtfqjonzie
|
||||||
mbrupupdghxlsyckwtfqjonsie
|
mbrupupdghxlsyckwtfqjonsie
|
||||||
mbrsvupdghxlzyckwtfqjonkie
|
mbrsvupdghxlzyckwtfqjonkie
|
||||||
mxruvgpdghxllyckwtfqjonsie
|
mxruvgpdghxllyckwtfqjonsie
|
||||||
mbrnvapdghxlzycbwtfqfonsie
|
mbrnvapdghxlzycbwtfqfonsie
|
||||||
mbrbxapdghxlzyckttfqjonsie
|
mbrbxapdghxlzyckttfqjonsie
|
||||||
mbnuvapdghxlzyxkwtmqjonsie
|
mbnuvapdghxlzyxkwtmqjonsie
|
||||||
mbrfvapdghjlzickwtfqjonsie
|
mbrfvapdghjlzickwtfqjonsie
|
||||||
mbhuvupdghxlzyxkwtfqjonsie
|
mbhuvupdghxlzyxkwtfqjonsie
|
||||||
mbrcvapdghxluyckwtfqjznsie
|
mbrcvapdghxluyckwtfqjznsie
|
||||||
mbruvapdghxlzyckwofqjoxsiz
|
mbruvapdghxlzyckwofqjoxsiz
|
||||||
mbrevapdghxloyckwtfqjonnie
|
mbrevapdghxloyckwtfqjonnie
|
||||||
mbruvipdghnlzyckwtfqjopsie
|
mbruvipdghnlzyckwtfqjopsie
|
||||||
mbxxvaptghxlzyckwtfqjonsie
|
mbxxvaptghxlzyckwtfqjonsie
|
||||||
mbruvcpdghxlztckwtjqjonsie
|
mbruvcpdghxlztckwtjqjonsie
|
||||||
mqruvlpdghxlzyckotfqjonsie
|
mqruvlpdghxlzyckotfqjonsie
|
||||||
mbruvapdgqxlzyckwtfqjpvsie
|
mbruvapdgqxlzyckwtfqjpvsie
|
||||||
mbruvapdgvxlzyjkwtfqjbnsie
|
mbruvapdgvxlzyjkwtfqjbnsie
|
||||||
mbruvapdghxlgyckwtfqcocsie
|
mbruvapdghxlgyckwtfqcocsie
|
||||||
mbruvapdghxkwyckwtfqjoqsie
|
mbruvapdghxkwyckwtfqjoqsie
|
||||||
mbrgvavdghxlzyckwxfqjonsie
|
mbrgvavdghxlzyckwxfqjonsie
|
||||||
qbruqapdgvxlzyckwtfqjonsie
|
qbruqapdgvxlzyckwtfqjonsie
|
||||||
mbauvapdghxlzgckwtfqjunsie
|
mbauvapdghxlzgckwtfqjunsie
|
||||||
mbruvapdgdxluyckwtfqjoosie
|
mbruvapdgdxluyckwtfqjoosie
|
||||||
mbruvapdghxlzykkwtfqwobsie
|
mbruvapdghxlzykkwtfqwobsie
|
||||||
mbruvapdghxlzhcnwtfqjonqie
|
mbruvapdghxlzhcnwtfqjonqie
|
||||||
mbruvapdghxlzycbhmfqjonsie
|
mbruvapdghxlzycbhmfqjonsie
|
||||||
mbruvapdghxluyczwtfqjontie
|
mbruvapdghxluyczwtfqjontie
|
||||||
mbruvapnghxlzyckwnfqjonbie
|
mbruvapnghxlzyckwnfqjonbie
|
||||||
moruvapdghxlzcckwtfqponsie
|
moruvapdghxlzcckwtfqponsie
|
||||||
mbruvapfgxxlzyckwtfqjunsie
|
mbruvapfgxxlzyckwtfqjunsie
|
||||||
mbruvapdghxlryckvtfejonsie
|
mbruvapdghxlryckvtfejonsie
|
||||||
mbrzvapdghxlzvcbwtfqjonsie
|
mbrzvapdghxlzvcbwtfqjonsie
|
||||||
mbruvapdgqxlzyckwcfqjonsce
|
mbruvapdgqxlzyckwcfqjonsce
|
||||||
abruvupdrhxlzyckwtfqjonsie
|
abruvupdrhxlzyckwtfqjonsie
|
||||||
mbrubaptghxlzyckwtfqjondie
|
mbrubaptghxlzyckwtfqjondie
|
||||||
mgruvapdgpxlzyckwtfijonsie
|
mgruvapdgpxlzyckwtfijonsie
|
||||||
mbruvapdghxczlckwtfujonsie
|
mbruvapdghxczlckwtfujonsie
|
||||||
mbruvapdgmmlzyckwtfqjonsir
|
mbruvapdgmmlzyckwtfqjonsir
|
||||||
mbruvapdhhxltyckwtfdjonsie
|
mbruvapdhhxltyckwtfdjonsie
|
||||||
mbruvapdghxlzyckwtfdjjnste
|
mbruvapdghxlzyckwtfdjjnste
|
||||||
mbrdvzpdghxlcyckwtfqjonsie
|
mbrdvzpdghxlcyckwtfqjonsie
|
||||||
mbruvapdghxlzyckwtnqbonsim
|
mbruvapdghxlzyckwtnqbonsim
|
||||||
mbrovapdghxlzyckwtfpjousie
|
mbrovapdghxlzyckwtfpjousie
|
||||||
mymuvapdghxlzyjkwtfqjonsie
|
mymuvapdghxlzyjkwtfqjonsie
|
||||||
mbpuvapdghxlzyckwtfljcnsie
|
mbpuvapdghxlzyckwtfljcnsie
|
||||||
mbrxvapdghxlzyclwtfqjonpie
|
mbrxvapdghxlzyclwtfqjonpie
|
||||||
mbrueapdghxlzyckwtfqjopsia
|
mbrueapdghxlzyckwtfqjopsia
|
||||||
mbruvapdghxlzycdwtfqjbfsie
|
mbruvapdghxlzycdwtfqjbfsie
|
||||||
tbruvavdghxlzyckwtmqjonsie
|
tbruvavdghxlzyckwtmqjonsie
|
||||||
mbduvapdghxlzyckwrfqjrnsie
|
mbduvapdghxlzyckwrfqjrnsie
|
||||||
mkrsvapughxlzyckwtfqjonsie
|
mkrsvapughxlzyckwtfqjonsie
|
||||||
mbruvapdghylzyckwtfqtolsie
|
mbruvapdghylzyckwtfqtolsie
|
||||||
mgruvapdglxldyckwtfqjonsie
|
mgruvapdglxldyckwtfqjonsie
|
||||||
mbrunapdghclzyckwtfqjonsiy
|
mbrunapdghclzyckwtfqjonsiy
|
||||||
mbruvapdgrxlxyckwtfgjonsie
|
mbruvapdgrxlxyckwtfgjonsie
|
||||||
mbruvapdghxpzbckftfqjonsie
|
mbruvapdghxpzbckftfqjonsie
|
||||||
mbruvcpdghxyzyckotfqjonsie
|
mbruvcpdghxyzyckotfqjonsie
|
||||||
mbruvapdghxlsyckwtfqcqnsie
|
mbruvapdghxlsyckwtfqcqnsie
|
||||||
mbruvapdghxlzzckwtfqjonskf
|
mbruvapdghxlzzckwtfqjonskf
|
||||||
mbruvppdghxlzfckwtfqjgnsie
|
mbruvppdghxlzfckwtfqjgnsie
|
||||||
mbhuvapdghxlzytkwtfqjonoie
|
mbhuvapdghxlzytkwtfqjonoie
|
||||||
mbruvapdghxlzvrkwtfqjjnsie
|
mbruvapdghxlzvrkwtfqjjnsie
|
||||||
mbmuvapdghxuzyckwtfqjonsze
|
mbmuvapdghxuzyckwtfqjonsze
|
||||||
mbruvapdghnlzycnwtfqjonsil
|
mbruvapdghnlzycnwtfqjonsil
|
||||||
mbruvapdgholzyckitfqjonsia
|
mbruvapdgholzyckitfqjonsia
|
||||||
mbruxapdghxlmyckwtfqbonsie
|
mbruxapdghxlmyckwtfqbonsie
|
||||||
mbauvapdgholzyckwtfqjolsie
|
mbauvapdgholzyckwtfqjolsie
|
||||||
mbruvapdghxlzyckwtfqjotslq
|
mbruvapdghxlzyckwtfqjotslq
|
||||||
dbrutapdghxlzyckwtfqjonsiv
|
dbrutapdghxlzyckwtfqjonsiv
|
||||||
mbruvapdzhxlyyckwtfbjonsie
|
mbruvapdzhxlyyckwtfbjonsie
|
||||||
mmruaapsghxlzyckwtfqjonsie
|
mmruaapsghxlzyckwtfqjonsie
|
||||||
mbruvaldgqxqzyckwtfqjonsie
|
mbruvaldgqxqzyckwtfqjonsie
|
||||||
mbruvaodghxdzyjkwtfqjonsie
|
mbruvaodghxdzyjkwtfqjonsie
|
||||||
mbrcmatdghxlzyckwtfqjonsie
|
mbrcmatdghxlzyckwtfqjonsie
|
||||||
mbrqvapdgtxlzycewtfqjonsie
|
mbrqvapdgtxlzycewtfqjonsie
|
||||||
mjruvapdghzlzyckwtfqjonrie
|
mjruvapdghzlzyckwtfqjonrie
|
||||||
mbruvapdghxopcckwtfqjonsie
|
mbruvapdghxopcckwtfqjonsie
|
||||||
mbruvapdghxszycwwtfqjoqsie
|
mbruvapdghxszycwwtfqjoqsie
|
||||||
mbruvapdgoxezyckwtjqjonsie
|
mbruvapdgoxezyckwtjqjonsie
|
||||||
@@ -1,50 +1,50 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::string equalLetters(std::string fileName) {
|
std::string equalLetters(std::string fileName) {
|
||||||
std::fstream input(fileName);
|
std::fstream input(fileName);
|
||||||
std::string line;
|
std::string line;
|
||||||
std::string a;
|
std::string a;
|
||||||
std::string b;
|
std::string b;
|
||||||
std::string answer;
|
std::string answer;
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
|
|
||||||
while (!input.eof()) {
|
while (!input.eof()) {
|
||||||
std::getline(input, line);
|
std::getline(input, line);
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < lines.size(); ++i) {
|
for (size_t i = 0; i < lines.size(); ++i) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
a = lines[i];
|
a = lines[i];
|
||||||
|
|
||||||
for (size_t j = i + 1; j < lines.size(); ++j) {
|
for (size_t j = i + 1; j < lines.size(); ++j) {
|
||||||
b = lines[j];
|
b = lines[j];
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
for (size_t k = 0; k < a.size(); ++k) {
|
for (size_t k = 0; k < a.size(); ++k) {
|
||||||
if (a[k] != b[k])
|
if (a[k] != b[k])
|
||||||
++count;
|
++count;
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (count == 1)
|
if (count == 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < a.size(); ++i) {
|
for (size_t i = 0; i < a.size(); ++i) {
|
||||||
if (a[i] == b[i])
|
if (a[i] == b[i])
|
||||||
answer += a[i];
|
answer += a[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
std::cout << "Found: " << equalLetters("input.txt") << std::endl;
|
std::cout << "Found: " << equalLetters("input.txt") << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,107 +1,107 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace challenge1 {
|
namespace challenge1 {
|
||||||
class Program {
|
class Program {
|
||||||
static string[] Lines {get; set;}
|
static string[] Lines {get; set;}
|
||||||
static List<Claim> Claims {get; set;}
|
static List<Claim> Claims {get; set;}
|
||||||
|
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
Claims = new List<Claim>();
|
Claims = new List<Claim>();
|
||||||
Console.WriteLine("Reading input.txt");
|
Console.WriteLine("Reading input.txt");
|
||||||
Lines = File.ReadAllLines("./input.txt");
|
Lines = File.ReadAllLines("./input.txt");
|
||||||
foreach (string line in Lines) {
|
foreach (string line in Lines) {
|
||||||
Claim current = new Claim(line);
|
Claim current = new Claim(line);
|
||||||
Claims.Add(current);
|
Claims.Add(current);
|
||||||
current.Print();
|
current.Print();
|
||||||
}
|
}
|
||||||
Fabric fabric = new Fabric(Claims);
|
Fabric fabric = new Fabric(Claims);
|
||||||
Console.WriteLine("Found: " + fabric.CalculateOverlaps() + " overlaps");
|
Console.WriteLine("Found: " + fabric.CalculateOverlaps() + " overlaps");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printArray(string[] arr) {
|
public static void printArray(string[] arr) {
|
||||||
foreach (string str in arr) {
|
foreach (string str in arr) {
|
||||||
Console.WriteLine(str);
|
Console.WriteLine(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Claim {
|
class Claim {
|
||||||
public int ID {get; set;}
|
public int ID {get; set;}
|
||||||
public int X {get; set;}
|
public int X {get; set;}
|
||||||
public int Y {get; set;}
|
public int Y {get; set;}
|
||||||
public int W {get; set;}
|
public int W {get; set;}
|
||||||
public int H {get; set;}
|
public int H {get; set;}
|
||||||
public string Source {get; set;}
|
public string Source {get; set;}
|
||||||
|
|
||||||
public Claim(string source) {
|
public Claim(string source) {
|
||||||
this.Source = source;
|
this.Source = source;
|
||||||
ParseSource();
|
ParseSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseSource() {
|
private void ParseSource() {
|
||||||
Console.WriteLine("Parsing: " + this.Source);
|
Console.WriteLine("Parsing: " + this.Source);
|
||||||
string[] source = this.Source.Split('#');
|
string[] source = this.Source.Split('#');
|
||||||
string[] idAndRest = source[1].Split('@');
|
string[] idAndRest = source[1].Split('@');
|
||||||
this.ID = int.Parse(idAndRest[0]);
|
this.ID = int.Parse(idAndRest[0]);
|
||||||
string[] fromSides = idAndRest[1].Split(',');
|
string[] fromSides = idAndRest[1].Split(',');
|
||||||
string[] afterColon = fromSides[1].Split(':');
|
string[] afterColon = fromSides[1].Split(':');
|
||||||
this.X = int.Parse(fromSides[0]);
|
this.X = int.Parse(fromSides[0]);
|
||||||
this.Y = int.Parse(afterColon[0]);
|
this.Y = int.Parse(afterColon[0]);
|
||||||
string[] dimensions = afterColon[1].Split('x');
|
string[] dimensions = afterColon[1].Split('x');
|
||||||
this.W = int.Parse(dimensions[0]);
|
this.W = int.Parse(dimensions[0]);
|
||||||
this.H = int.Parse(dimensions[1]);
|
this.H = int.Parse(dimensions[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Print() {
|
public void Print() {
|
||||||
Console.WriteLine("Claim ID: " + this.ID);
|
Console.WriteLine("Claim ID: " + this.ID);
|
||||||
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
|
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
|
||||||
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
|
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
|
||||||
Console.WriteLine("Parsed from source: " + this.Source);
|
Console.WriteLine("Parsed from source: " + this.Source);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Fabric {
|
class Fabric {
|
||||||
public List<Claim> Claims;
|
public List<Claim> Claims;
|
||||||
|
|
||||||
private int[,] Board;
|
private int[,] Board;
|
||||||
|
|
||||||
public Fabric(List<Claim> claims) {
|
public Fabric(List<Claim> claims) {
|
||||||
this.Claims = claims;
|
this.Claims = claims;
|
||||||
this.Board = new int[10000, 10000];
|
this.Board = new int[10000, 10000];
|
||||||
|
|
||||||
for (int i = 0; i < 10000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
for (int j = 0; j < 10000; j++) {
|
for (int j = 0; j < 10000; j++) {
|
||||||
Board[i, j] = 0;
|
Board[i, j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CalculateOverlaps() {
|
public int CalculateOverlaps() {
|
||||||
int overlaps = 0;
|
int overlaps = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (Claim claim in this.Claims) {
|
foreach (Claim claim in this.Claims) {
|
||||||
Console.WriteLine("Processing claim ID: " + claim.ID);
|
Console.WriteLine("Processing claim ID: " + claim.ID);
|
||||||
|
|
||||||
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
||||||
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
||||||
Board[x, y]++;
|
Board[x, y]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 10000; i++) {
|
for (i = 0; i < 10000; i++) {
|
||||||
for (int j = 0; j < 10000; j++) {
|
for (int j = 0; j < 10000; j++) {
|
||||||
if (Board[i,j] > 1) overlaps++;
|
if (Board[i,j] > 1) overlaps++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return overlaps;
|
return overlaps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,40 @@
|
|||||||
--- Day 3: No Matter How You Slice It ---
|
--- 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 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.
|
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:
|
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 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 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 width of the rectangle in inches.
|
||||||
The height 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:
|
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:
|
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
|
#1 @ 1,3: 4x4
|
||||||
#2 @ 3,1: 4x4
|
#2 @ 3,1: 4x4
|
||||||
#3 @ 5,5: 2x2
|
#3 @ 5,5: 2x2
|
||||||
Visually, these claim the following areas:
|
Visually, these claim the following areas:
|
||||||
|
|
||||||
........
|
........
|
||||||
...2222.
|
...2222.
|
||||||
...2222.
|
...2222.
|
||||||
.11XX22.
|
.11XX22.
|
||||||
.11XX22.
|
.11XX22.
|
||||||
.111133.
|
.111133.
|
||||||
.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.)
|
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?
|
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?
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,115 +1,115 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace challenge2 {
|
namespace challenge2 {
|
||||||
class Program {
|
class Program {
|
||||||
static string[] Lines {get; set;}
|
static string[] Lines {get; set;}
|
||||||
static List<Claim> Claims {get; set;}
|
static List<Claim> Claims {get; set;}
|
||||||
|
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
Claims = new List<Claim>();
|
Claims = new List<Claim>();
|
||||||
Console.WriteLine("Reading input.txt");
|
Console.WriteLine("Reading input.txt");
|
||||||
Lines = File.ReadAllLines("./input.txt");
|
Lines = File.ReadAllLines("./input.txt");
|
||||||
foreach (string line in Lines) {
|
foreach (string line in Lines) {
|
||||||
Claim current = new Claim(line);
|
Claim current = new Claim(line);
|
||||||
Claims.Add(current);
|
Claims.Add(current);
|
||||||
current.Print();
|
current.Print();
|
||||||
}
|
}
|
||||||
Fabric fabric = new Fabric(Claims);
|
Fabric fabric = new Fabric(Claims);
|
||||||
Console.WriteLine("Found ID: " + fabric.CalculateOverlaps());
|
Console.WriteLine("Found ID: " + fabric.CalculateOverlaps());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printArray(string[] arr) {
|
public static void printArray(string[] arr) {
|
||||||
foreach (string str in arr) {
|
foreach (string str in arr) {
|
||||||
Console.WriteLine(str);
|
Console.WriteLine(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Claim {
|
class Claim {
|
||||||
public int ID {get; set;}
|
public int ID {get; set;}
|
||||||
public int X {get; set;}
|
public int X {get; set;}
|
||||||
public int Y {get; set;}
|
public int Y {get; set;}
|
||||||
public int W {get; set;}
|
public int W {get; set;}
|
||||||
public int H {get; set;}
|
public int H {get; set;}
|
||||||
public string Source {get; set;}
|
public string Source {get; set;}
|
||||||
|
|
||||||
public Claim(string source) {
|
public Claim(string source) {
|
||||||
this.Source = source;
|
this.Source = source;
|
||||||
ParseSource();
|
ParseSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseSource() {
|
private void ParseSource() {
|
||||||
Console.WriteLine("Parsing: " + this.Source);
|
Console.WriteLine("Parsing: " + this.Source);
|
||||||
string[] source = this.Source.Split('#');
|
string[] source = this.Source.Split('#');
|
||||||
string[] idAndRest = source[1].Split('@');
|
string[] idAndRest = source[1].Split('@');
|
||||||
this.ID = int.Parse(idAndRest[0]);
|
this.ID = int.Parse(idAndRest[0]);
|
||||||
string[] fromSides = idAndRest[1].Split(',');
|
string[] fromSides = idAndRest[1].Split(',');
|
||||||
string[] afterColon = fromSides[1].Split(':');
|
string[] afterColon = fromSides[1].Split(':');
|
||||||
this.X = int.Parse(fromSides[0]);
|
this.X = int.Parse(fromSides[0]);
|
||||||
this.Y = int.Parse(afterColon[0]);
|
this.Y = int.Parse(afterColon[0]);
|
||||||
string[] dimensions = afterColon[1].Split('x');
|
string[] dimensions = afterColon[1].Split('x');
|
||||||
this.W = int.Parse(dimensions[0]);
|
this.W = int.Parse(dimensions[0]);
|
||||||
this.H = int.Parse(dimensions[1]);
|
this.H = int.Parse(dimensions[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Print() {
|
public void Print() {
|
||||||
Console.WriteLine("Claim ID: " + this.ID);
|
Console.WriteLine("Claim ID: " + this.ID);
|
||||||
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
|
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
|
||||||
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
|
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
|
||||||
Console.WriteLine("Parsed from source: " + this.Source);
|
Console.WriteLine("Parsed from source: " + this.Source);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Fabric {
|
class Fabric {
|
||||||
public List<Claim> Claims;
|
public List<Claim> Claims;
|
||||||
|
|
||||||
private int[,] Board;
|
private int[,] Board;
|
||||||
|
|
||||||
public Fabric(List<Claim> claims) {
|
public Fabric(List<Claim> claims) {
|
||||||
this.Claims = claims;
|
this.Claims = claims;
|
||||||
this.Board = new int[10000, 10000];
|
this.Board = new int[10000, 10000];
|
||||||
|
|
||||||
for (int i = 0; i < 10000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
for (int j = 0; j < 10000; j++) {
|
for (int j = 0; j < 10000; j++) {
|
||||||
Board[i, j] = 0;
|
Board[i, j] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CalculateOverlaps() {
|
public int CalculateOverlaps() {
|
||||||
int overlaps = 0;
|
int overlaps = 0;
|
||||||
|
|
||||||
foreach (Claim claim in this.Claims) {
|
foreach (Claim claim in this.Claims) {
|
||||||
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
||||||
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
||||||
Board[x, y]++;
|
Board[x, y]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Claim claim in this.Claims) {
|
foreach (Claim claim in this.Claims) {
|
||||||
bool isValid = true;
|
bool isValid = true;
|
||||||
Console.WriteLine("Processing claim ID: " + claim.ID);
|
Console.WriteLine("Processing claim ID: " + claim.ID);
|
||||||
|
|
||||||
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
||||||
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
||||||
if(this.Board[x,y] != 1) {
|
if(this.Board[x,y] != 1) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isValid) break;
|
if (!isValid) break;
|
||||||
}
|
}
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
overlaps = claim.ID;
|
overlaps = claim.ID;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return overlaps;
|
return overlaps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
Your puzzle answer was 109143.
|
Your puzzle answer was 109143.
|
||||||
|
|
||||||
The first half of this puzzle is complete! It provides one gold star: *
|
The first half of this puzzle is complete! It provides one gold star: *
|
||||||
|
|
||||||
--- Part Two ---
|
--- 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!
|
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.
|
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?
|
What is the ID of the only claim that doesn't overlap?
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
72
2018/4thDay/challenge1/.vscode/settings.json
vendored
72
2018/4thDay/challenge1/.vscode/settings.json
vendored
@@ -1,37 +1,37 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"cctype": "cpp",
|
"cctype": "cpp",
|
||||||
"clocale": "cpp",
|
"clocale": "cpp",
|
||||||
"cmath": "cpp",
|
"cmath": "cpp",
|
||||||
"cstddef": "cpp",
|
"cstddef": "cpp",
|
||||||
"cstdio": "cpp",
|
"cstdio": "cpp",
|
||||||
"cstdlib": "cpp",
|
"cstdlib": "cpp",
|
||||||
"cwchar": "cpp",
|
"cwchar": "cpp",
|
||||||
"cwctype": "cpp",
|
"cwctype": "cpp",
|
||||||
"array": "cpp",
|
"array": "cpp",
|
||||||
"*.tcc": "cpp",
|
"*.tcc": "cpp",
|
||||||
"cstdint": "cpp",
|
"cstdint": "cpp",
|
||||||
"deque": "cpp",
|
"deque": "cpp",
|
||||||
"unordered_map": "cpp",
|
"unordered_map": "cpp",
|
||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"exception": "cpp",
|
"exception": "cpp",
|
||||||
"fstream": "cpp",
|
"fstream": "cpp",
|
||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"iosfwd": "cpp",
|
"iosfwd": "cpp",
|
||||||
"iostream": "cpp",
|
"iostream": "cpp",
|
||||||
"istream": "cpp",
|
"istream": "cpp",
|
||||||
"limits": "cpp",
|
"limits": "cpp",
|
||||||
"new": "cpp",
|
"new": "cpp",
|
||||||
"optional": "cpp",
|
"optional": "cpp",
|
||||||
"ostream": "cpp",
|
"ostream": "cpp",
|
||||||
"sstream": "cpp",
|
"sstream": "cpp",
|
||||||
"stdexcept": "cpp",
|
"stdexcept": "cpp",
|
||||||
"streambuf": "cpp",
|
"streambuf": "cpp",
|
||||||
"string_view": "cpp",
|
"string_view": "cpp",
|
||||||
"system_error": "cpp",
|
"system_error": "cpp",
|
||||||
"type_traits": "cpp",
|
"type_traits": "cpp",
|
||||||
"tuple": "cpp",
|
"tuple": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"utility": "cpp"
|
"utility": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,49 @@
|
|||||||
--- Day 4: Repose Record ---
|
--- 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.
|
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).
|
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:
|
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:00] Guard #10 begins shift
|
||||||
[1518-11-01 00:05] falls asleep
|
[1518-11-01 00:05] falls asleep
|
||||||
[1518-11-01 00:25] wakes up
|
[1518-11-01 00:25] wakes up
|
||||||
[1518-11-01 00:30] falls asleep
|
[1518-11-01 00:30] falls asleep
|
||||||
[1518-11-01 00:55] wakes up
|
[1518-11-01 00:55] wakes up
|
||||||
[1518-11-01 23:58] Guard #99 begins shift
|
[1518-11-01 23:58] Guard #99 begins shift
|
||||||
[1518-11-02 00:40] falls asleep
|
[1518-11-02 00:40] falls asleep
|
||||||
[1518-11-02 00:50] wakes up
|
[1518-11-02 00:50] wakes up
|
||||||
[1518-11-03 00:05] Guard #10 begins shift
|
[1518-11-03 00:05] Guard #10 begins shift
|
||||||
[1518-11-03 00:24] falls asleep
|
[1518-11-03 00:24] falls asleep
|
||||||
[1518-11-03 00:29] wakes up
|
[1518-11-03 00:29] wakes up
|
||||||
[1518-11-04 00:02] Guard #99 begins shift
|
[1518-11-04 00:02] Guard #99 begins shift
|
||||||
[1518-11-04 00:36] falls asleep
|
[1518-11-04 00:36] falls asleep
|
||||||
[1518-11-04 00:46] wakes up
|
[1518-11-04 00:46] wakes up
|
||||||
[1518-11-05 00:03] Guard #99 begins shift
|
[1518-11-05 00:03] Guard #99 begins shift
|
||||||
[1518-11-05 00:45] falls asleep
|
[1518-11-05 00:45] falls asleep
|
||||||
[1518-11-05 00:55] wakes up
|
[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.
|
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:
|
Visually, these records show that the guards are asleep at these times:
|
||||||
|
|
||||||
Date ID Minute
|
Date ID Minute
|
||||||
000000000011111111112222222222333333333344444444445555555555
|
000000000011111111112222222222333333333344444444445555555555
|
||||||
012345678901234567890123456789012345678901234567890123456789
|
012345678901234567890123456789012345678901234567890123456789
|
||||||
11-01 #10 .....####################.....#########################.....
|
11-01 #10 .....####################.....#########################.....
|
||||||
11-02 #99 ........................................##########..........
|
11-02 #99 ........................................##########..........
|
||||||
11-03 #10 ........................#####...............................
|
11-03 #10 ........................#####...............................
|
||||||
11-04 #99 ....................................##########..............
|
11-04 #99 ....................................##########..............
|
||||||
11-05 #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 #.
|
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.
|
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.
|
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?
|
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).
|
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.
|
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.)
|
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.)
|
||||||
@@ -1,71 +1,71 @@
|
|||||||
class Guard {
|
class Guard {
|
||||||
constructor (id) {
|
constructor (id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
|
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
|
||||||
this.fellAsleepAt = null;
|
this.fellAsleepAt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep (fellAsleepAt) {
|
sleep (fellAsleepAt) {
|
||||||
this.fellAsleepAt = fellAsleepAt;
|
this.fellAsleepAt = fellAsleepAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
awake (awokeAt) {
|
awake (awokeAt) {
|
||||||
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
|
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
|
||||||
this.minutesAsleep[i] += 1;
|
this.minutesAsleep[i] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get totalSleepMinutes () {
|
get totalSleepMinutes () {
|
||||||
return this.minutesAsleep.reduce((a, b) => a + b, 0);
|
return this.minutesAsleep.reduce((a, b) => a + b, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
get sleepiestMinute () {
|
get sleepiestMinute () {
|
||||||
return this.minutesAsleep
|
return this.minutesAsleep
|
||||||
.map((value, index) => ({ index, value }))
|
.map((value, index) => ({ index, value }))
|
||||||
.sort((a, b) => b.value - a.value)[0].index;
|
.sort((a, b) => b.value - a.value)[0].index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sleep = (input) => {
|
const sleep = (input) => {
|
||||||
const guards = {};
|
const guards = {};
|
||||||
const schedule = input
|
const schedule = input
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((x) => x.trim())
|
.map((x) => x.trim())
|
||||||
.sort()
|
.sort()
|
||||||
.map((x) => {
|
.map((x) => {
|
||||||
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
|
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
minute: +parts[5],
|
minute: +parts[5],
|
||||||
message: parts[6],
|
message: parts[6],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let currentGuard = null;
|
let currentGuard = null;
|
||||||
|
|
||||||
for (let i = 0; i < schedule.length; i++) {
|
for (let i = 0; i < schedule.length; i++) {
|
||||||
const { message, minute } = schedule[i];
|
const { message, minute } = schedule[i];
|
||||||
|
|
||||||
if (/Guard/.test(message)) {
|
if (/Guard/.test(message)) {
|
||||||
const parts = message.match(/Guard #(\d+) begins shift/);
|
const parts = message.match(/Guard #(\d+) begins shift/);
|
||||||
const guardId = +parts[1];
|
const guardId = +parts[1];
|
||||||
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
|
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
|
||||||
|
|
||||||
currentGuard = guards[guardId] = guard;
|
currentGuard = guards[guardId] = guard;
|
||||||
} else if (message === 'falls asleep') {
|
} else if (message === 'falls asleep') {
|
||||||
currentGuard.sleep(minute);
|
currentGuard.sleep(minute);
|
||||||
} else if (message === 'wakes up') {
|
} else if (message === 'wakes up') {
|
||||||
currentGuard.awake(minute);
|
currentGuard.awake(minute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const sleepiestGuard = Object
|
const sleepiestGuard = Object
|
||||||
.keys(guards)
|
.keys(guards)
|
||||||
.map((guardId) => guards[guardId])
|
.map((guardId) => guards[guardId])
|
||||||
.sort((a, b) => b.totalSleepMinutes - a.totalSleepMinutes)[0];
|
.sort((a, b) => b.totalSleepMinutes - a.totalSleepMinutes)[0];
|
||||||
|
|
||||||
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
|
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
console.log(sleep(fs.readFileSync("input.txt").toString()));
|
console.log(sleep(fs.readFileSync("input.txt").toString()));
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,180 +1,180 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
enum class State {begin, sleep, awaken};
|
enum class State {begin, sleep, awaken};
|
||||||
struct Action
|
struct Action
|
||||||
{
|
{
|
||||||
State state;
|
State state;
|
||||||
int64_t guard_id;
|
int64_t guard_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
int64_t month, day, hour, minute;
|
int64_t month, day, hour, minute;
|
||||||
Action action;
|
Action action;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::istream &operator>>(std::istream &is, Action &action)
|
std::istream &operator>>(std::istream &is, Action &action)
|
||||||
{
|
{
|
||||||
std::string element;
|
std::string element;
|
||||||
is >> element;
|
is >> element;
|
||||||
if(element=="Guard")
|
if(element=="Guard")
|
||||||
{
|
{
|
||||||
action.state=State::begin;
|
action.state=State::begin;
|
||||||
char c;
|
char c;
|
||||||
is >> c >> action.guard_id;
|
is >> c >> action.guard_id;
|
||||||
}
|
}
|
||||||
else if(element=="falls")
|
else if(element=="falls")
|
||||||
{
|
{
|
||||||
action.state=State::sleep;
|
action.state=State::sleep;
|
||||||
}
|
}
|
||||||
else if(element=="wakes")
|
else if(element=="wakes")
|
||||||
{
|
{
|
||||||
action.state=State::awaken;
|
action.state=State::awaken;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid input");
|
throw std::runtime_error("Invalid input");
|
||||||
}
|
}
|
||||||
std::getline(is,element);
|
std::getline(is,element);
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream &operator>>(std::istream &is, Event &event)
|
std::istream &operator>>(std::istream &is, Event &event)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
int64_t year;
|
int64_t year;
|
||||||
is >> c;
|
is >> c;
|
||||||
if(is.good())
|
if(is.good())
|
||||||
{
|
{
|
||||||
is >> year >> c >> event.month >> c >> event.day
|
is >> year >> c >> event.month >> c >> event.day
|
||||||
>> event.hour >> c >> event.minute >> c
|
>> event.hour >> c >> event.minute >> c
|
||||||
>> event.action;
|
>> event.action;
|
||||||
|
|
||||||
if(event.hour==23)
|
if(event.hour==23)
|
||||||
{
|
{
|
||||||
event.minute=0;
|
event.minute=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Action &action)
|
std::ostream &operator<<(std::ostream &os, const Action &action)
|
||||||
{
|
{
|
||||||
switch(action.state)
|
switch(action.state)
|
||||||
{
|
{
|
||||||
case State::begin:
|
case State::begin:
|
||||||
os << "Guard #" << action.guard_id << " begins shift";
|
os << "Guard #" << action.guard_id << " begins shift";
|
||||||
break;
|
break;
|
||||||
case State::sleep:
|
case State::sleep:
|
||||||
os << "falls asleep";
|
os << "falls asleep";
|
||||||
break;
|
break;
|
||||||
case State::awaken:
|
case State::awaken:
|
||||||
os << "wakes up";
|
os << "wakes up";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
os << "What?";
|
os << "What?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Event &event)
|
std::ostream &operator<<(std::ostream &os, const Event &event)
|
||||||
{
|
{
|
||||||
os << "[1518-"
|
os << "[1518-"
|
||||||
<< std::setw(2) << std::setfill('0') << event.month << "-"
|
<< std::setw(2) << std::setfill('0') << event.month << "-"
|
||||||
<< std::setw(2) << std::setfill('0') << event.day << " "
|
<< std::setw(2) << std::setfill('0') << event.day << " "
|
||||||
<< std::setw(2) << std::setfill('0') << event.hour << ":"
|
<< std::setw(2) << std::setfill('0') << event.hour << ":"
|
||||||
<< std::setw(2) << std::setfill('0') << event.minute << "] "
|
<< std::setw(2) << std::setfill('0') << event.minute << "] "
|
||||||
<< event.action;
|
<< event.action;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int64_t,int64_t> max_incident(const std::vector<std::pair<int64_t,
|
std::pair<int64_t,int64_t> max_incident(const std::vector<std::pair<int64_t,
|
||||||
int64_t>> &incidents)
|
int64_t>> &incidents)
|
||||||
{
|
{
|
||||||
std::vector<int64_t> sleep_incidents(60,0);
|
std::vector<int64_t> sleep_incidents(60,0);
|
||||||
for(auto ×: incidents)
|
for(auto ×: incidents)
|
||||||
{
|
{
|
||||||
for(size_t time=times.first; time<times.second; ++time)
|
for(size_t time=times.first; time<times.second; ++time)
|
||||||
{ ++(sleep_incidents[time]); }
|
{ ++(sleep_incidents[time]); }
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t max_incidents(0), max_minute(0);
|
int64_t max_incidents(0), max_minute(0);
|
||||||
for(size_t time=0; time<sleep_incidents.size(); ++time)
|
for(size_t time=0; time<sleep_incidents.size(); ++time)
|
||||||
{
|
{
|
||||||
if(max_incidents<sleep_incidents[time])
|
if(max_incidents<sleep_incidents[time])
|
||||||
{
|
{
|
||||||
max_incidents=sleep_incidents[time];
|
max_incidents=sleep_incidents[time];
|
||||||
max_minute=time;
|
max_minute=time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::make_pair(max_incidents,max_minute);
|
return std::make_pair(max_incidents,max_minute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::ifstream infile(argv[1]);
|
std::ifstream infile(argv[1]);
|
||||||
std::vector<Event> events(std::istream_iterator<Event>(infile), {});
|
std::vector<Event> events(std::istream_iterator<Event>(infile), {});
|
||||||
|
|
||||||
std::map<int,std::vector<std::pair<int64_t,int64_t>>> guards;
|
std::map<int,std::vector<std::pair<int64_t,int64_t>>> guards;
|
||||||
|
|
||||||
int64_t guard_id;
|
int64_t guard_id;
|
||||||
int64_t start(-1);
|
int64_t start(-1);
|
||||||
for(auto &event: events)
|
for(auto &event: events)
|
||||||
{
|
{
|
||||||
switch(event.action.state)
|
switch(event.action.state)
|
||||||
{
|
{
|
||||||
case State::begin:
|
case State::begin:
|
||||||
guard_id=event.action.guard_id;
|
guard_id=event.action.guard_id;
|
||||||
break;
|
break;
|
||||||
case State::sleep:
|
case State::sleep:
|
||||||
start=event.minute;
|
start=event.minute;
|
||||||
break;
|
break;
|
||||||
case State::awaken:
|
case State::awaken:
|
||||||
guards[guard_id].emplace_back(start,event.minute);
|
guards[guard_id].emplace_back(start,event.minute);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t max_time_guard, max_time(0);
|
int64_t max_time_guard, max_time(0);
|
||||||
for(auto &guard: guards)
|
for(auto &guard: guards)
|
||||||
{
|
{
|
||||||
int64_t total_time(0);
|
int64_t total_time(0);
|
||||||
for(auto &time: guard.second)
|
for(auto &time: guard.second)
|
||||||
{
|
{
|
||||||
total_time+=time.second-time.first;
|
total_time+=time.second-time.first;
|
||||||
}
|
}
|
||||||
if(total_time>max_time)
|
if(total_time>max_time)
|
||||||
{
|
{
|
||||||
max_time_guard=guard.first;
|
max_time_guard=guard.first;
|
||||||
max_time=total_time;
|
max_time=total_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto [max_incidents,max_minute]=max_incident(guards[max_time_guard]);
|
auto [max_incidents,max_minute]=max_incident(guards[max_time_guard]);
|
||||||
std::cout << "Part 1: " << (max_minute*max_time_guard) << "\n";
|
std::cout << "Part 1: " << (max_minute*max_time_guard) << "\n";
|
||||||
|
|
||||||
std::vector<int64_t> num_incidents(guards.size());
|
std::vector<int64_t> num_incidents(guards.size());
|
||||||
int64_t max_guard_incidents(0), max_guard_minute(0), max_guard_id(-1);
|
int64_t max_guard_incidents(0), max_guard_minute(0), max_guard_id(-1);
|
||||||
for(auto &guard: guards)
|
for(auto &guard: guards)
|
||||||
{
|
{
|
||||||
auto [incidents,minute]=max_incident(guard.second);
|
auto [incidents,minute]=max_incident(guard.second);
|
||||||
if(incidents>max_guard_incidents)
|
if(incidents>max_guard_incidents)
|
||||||
{
|
{
|
||||||
max_guard_incidents=incidents;
|
max_guard_incidents=incidents;
|
||||||
max_guard_minute=minute;
|
max_guard_minute=minute;
|
||||||
max_guard_id=guard.first;
|
max_guard_id=guard.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Part 2: " << (max_guard_id * max_guard_minute) << "\n";
|
std::cout << "Part 2: " << (max_guard_id * max_guard_minute) << "\n";
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
Strategy 2: Of all guards, which guard is most frequently asleep on the same minute?
|
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.)
|
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.)
|
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.)
|
||||||
|
|
||||||
|
|||||||
@@ -1,68 +1,68 @@
|
|||||||
class Guard {
|
class Guard {
|
||||||
constructor (id) {
|
constructor (id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
|
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
|
||||||
this.fellAsleepAt = null;
|
this.fellAsleepAt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep (fellAsleepAt) {
|
sleep (fellAsleepAt) {
|
||||||
this.fellAsleepAt = fellAsleepAt;
|
this.fellAsleepAt = fellAsleepAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
awake (awokeAt) {
|
awake (awokeAt) {
|
||||||
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
|
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
|
||||||
this.minutesAsleep[i] += 1;
|
this.minutesAsleep[i] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get sleepiestMinute () {
|
get sleepiestMinute () {
|
||||||
return this.minutesAsleep
|
return this.minutesAsleep
|
||||||
.map((value, index) => ({ index, value }))
|
.map((value, index) => ({ index, value }))
|
||||||
.sort((a, b) => b.value - a.value)[0].index;
|
.sort((a, b) => b.value - a.value)[0].index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sleep = (input) => {
|
const sleep = (input) => {
|
||||||
const guards = {};
|
const guards = {};
|
||||||
const schedule = input
|
const schedule = input
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((x) => x.trim())
|
.map((x) => x.trim())
|
||||||
.sort()
|
.sort()
|
||||||
.map((x) => {
|
.map((x) => {
|
||||||
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
|
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
minute: +parts[5],
|
minute: +parts[5],
|
||||||
message: parts[6],
|
message: parts[6],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let currentGuard = null;
|
let currentGuard = null;
|
||||||
|
|
||||||
for (let i = 0; i < schedule.length; i++) {
|
for (let i = 0; i < schedule.length; i++) {
|
||||||
const { message, minute } = schedule[i];
|
const { message, minute } = schedule[i];
|
||||||
|
|
||||||
if (/Guard/.test(message)) {
|
if (/Guard/.test(message)) {
|
||||||
const parts = message.match(/Guard #(\d+) begins shift/);
|
const parts = message.match(/Guard #(\d+) begins shift/);
|
||||||
const guardId = +parts[1];
|
const guardId = +parts[1];
|
||||||
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
|
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
|
||||||
|
|
||||||
currentGuard = guards[guardId] = guard;
|
currentGuard = guards[guardId] = guard;
|
||||||
} else if (message === 'falls asleep') {
|
} else if (message === 'falls asleep') {
|
||||||
currentGuard.sleep(minute);
|
currentGuard.sleep(minute);
|
||||||
} else if (message === 'wakes up') {
|
} else if (message === 'wakes up') {
|
||||||
currentGuard.awake(minute);
|
currentGuard.awake(minute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sleepiestGuard = Object
|
const sleepiestGuard = Object
|
||||||
.keys(guards)
|
.keys(guards)
|
||||||
.map((guardId) => guards[guardId])
|
.map((guardId) => guards[guardId])
|
||||||
.sort((a, b) => b.minutesAsleep[b.sleepiestMinute] -
|
.sort((a, b) => b.minutesAsleep[b.sleepiestMinute] -
|
||||||
a.minutesAsleep[a.sleepiestMinute])[0];
|
a.minutesAsleep[a.sleepiestMinute])[0];
|
||||||
|
|
||||||
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
|
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
console.log(sleep(fs.readFileSync("input.txt").toString()));
|
console.log(sleep(fs.readFileSync("input.txt").toString()));
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
8
2018/5thDay/.vscode/settings.json
vendored
8
2018/5thDay/.vscode/settings.json
vendored
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"ostream": "cpp"
|
"ostream": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
--- Day 5: Alchemical Reduction ---
|
--- 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.
|
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).
|
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.
|
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:
|
For example:
|
||||||
|
|
||||||
In aA, a and A react, leaving nothing behind.
|
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 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 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.
|
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:
|
Now, consider a larger example, dabAcCaCBAcCcaDA:
|
||||||
|
|
||||||
dabAcCaCBAcCcaDA The first 'cC' is removed.
|
dabAcCaCBAcCcaDA The first 'cC' is removed.
|
||||||
dabAaCBAcCcaDA This creates 'Aa', which is removed.
|
dabAaCBAcCcaDA This creates 'Aa', which is removed.
|
||||||
dabCBAcCcaDA Either 'cC' or 'Cc' are removed (the result is the same).
|
dabCBAcCcaDA Either 'cC' or 'Cc' are removed (the result is the same).
|
||||||
dabCBAcaDA No further actions can be taken.
|
dabCBAcaDA No further actions can be taken.
|
||||||
After all possible reactions, the resulting polymer contains 10 units.
|
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.)
|
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.)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const day4 = require('./istolethisfromsomeone');
|
const day4 = require('./istolethisfromsomeone');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
console.log('Part 1: ' + day4.part1(fs.readFileSync('input.txt').toString()));
|
console.log('Part 1: ' + day4.part1(fs.readFileSync('input.txt').toString()));
|
||||||
console.log('Part 2: ' + day4.part2(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
@@ -1,44 +1,44 @@
|
|||||||
function part1(data) {
|
function part1(data) {
|
||||||
const polymer = data.split("");
|
const polymer = data.split("");
|
||||||
const removeChar = ""; // No removal
|
const removeChar = ""; // No removal
|
||||||
const stack = collapsePloymer(polymer, removeChar);
|
const stack = collapsePloymer(polymer, removeChar);
|
||||||
return stack.length;
|
return stack.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function collapsePloymer(ploymerChars, removeChar) {
|
function collapsePloymer(ploymerChars, removeChar) {
|
||||||
const stack = [];
|
const stack = [];
|
||||||
for (let i = 0; i < ploymerChars.length; i++) {
|
for (let i = 0; i < ploymerChars.length; i++) {
|
||||||
const char = ploymerChars[i];
|
const char = ploymerChars[i];
|
||||||
if (char.toLowerCase() === removeChar.toLowerCase()) {
|
if (char.toLowerCase() === removeChar.toLowerCase()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const last = stack.pop();
|
const last = stack.pop();
|
||||||
if (!last) {
|
if (!last) {
|
||||||
stack.push(char);
|
stack.push(char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (last.toLowerCase() === char.toLowerCase() && last !== char) {
|
if (last.toLowerCase() === char.toLowerCase() && last !== char) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
stack.push(last);
|
stack.push(last);
|
||||||
stack.push(char);
|
stack.push(char);
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
function part2(data) {
|
function part2(data) {
|
||||||
const polymer = data.split("");
|
const polymer = data.split("");
|
||||||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
||||||
const collapsedPolymers = alphabet.map(letter =>
|
const collapsedPolymers = alphabet.map(letter =>
|
||||||
collapsePloymer(polymer, letter)
|
collapsePloymer(polymer, letter)
|
||||||
);
|
);
|
||||||
const shortestCollapse = collapsedPolymers.reduce((longest, curr) =>
|
const shortestCollapse = collapsedPolymers.reduce((longest, curr) =>
|
||||||
longest.length < curr.length ? longest : curr
|
longest.length < curr.length ? longest : curr
|
||||||
);
|
);
|
||||||
return shortestCollapse.length;
|
return shortestCollapse.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
part1: part1,
|
part1: part1,
|
||||||
part2: part2
|
part2: part2
|
||||||
};
|
};
|
||||||
@@ -1,43 +1,43 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
if (argc != 2) return 0;
|
if (argc != 2) return 0;
|
||||||
|
|
||||||
std::fstream input;
|
std::fstream input;
|
||||||
input.open(*(argv + 1));
|
input.open(*(argv + 1));
|
||||||
|
|
||||||
std::string polymerString;
|
std::string polymerString;
|
||||||
std::getline(input, polymerString);
|
std::getline(input, polymerString);
|
||||||
|
|
||||||
while (!false) {
|
while (!false) {
|
||||||
int numOfMods = 0;
|
int numOfMods = 0;
|
||||||
std::string eh = "";
|
std::string eh = "";
|
||||||
for (unsigned int i = 0; i < polymerString.length() - 1; i++) {
|
for (unsigned int i = 0; i < polymerString.length() - 1; i++) {
|
||||||
if (islower((char)polymerString[i])) {
|
if (islower((char)polymerString[i])) {
|
||||||
if (toupper((char)polymerString[i]) == (char)polymerString[i+1]) {
|
if (toupper((char)polymerString[i]) == (char)polymerString[i+1]) {
|
||||||
eh += polymerString.substr(0, i);
|
eh += polymerString.substr(0, i);
|
||||||
eh += polymerString.substr(i + 2, polymerString.length());
|
eh += polymerString.substr(i + 2, polymerString.length());
|
||||||
numOfMods++;
|
numOfMods++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isupper((char)polymerString[i])) {
|
if (isupper((char)polymerString[i])) {
|
||||||
if (tolower((char)polymerString[i]) == (char)polymerString[i+1]) {
|
if (tolower((char)polymerString[i]) == (char)polymerString[i+1]) {
|
||||||
eh += polymerString.substr(0, i);
|
eh += polymerString.substr(0, i);
|
||||||
eh += polymerString.substr(i + 2, polymerString.length());
|
eh += polymerString.substr(i + 2, polymerString.length());
|
||||||
numOfMods++;
|
numOfMods++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (eh != "") {
|
if (eh != "") {
|
||||||
polymerString = eh;
|
polymerString = eh;
|
||||||
}
|
}
|
||||||
std::cout << "Current length: " <<polymerString.length() << std::endl;
|
std::cout << "Current length: " <<polymerString.length() << std::endl;
|
||||||
if (numOfMods == 0) break;
|
if (numOfMods == 0) break;
|
||||||
}
|
}
|
||||||
std::cout << "Found polymers: " << polymerString << std::endl;
|
std::cout << "Found polymers: " << polymerString << std::endl;
|
||||||
std::cout << "At length: " << polymerString.length() << std::endl;
|
std::cout << "At length: " << polymerString.length() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
Time to improve the polymer.
|
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.
|
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:
|
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 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 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 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.
|
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.
|
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?
|
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
@@ -1,81 +1,81 @@
|
|||||||
--- Day 6: Chronal Coordinates ---
|
--- Day 6: Chronal Coordinates ---
|
||||||
The device on your wrist beeps several times, and once again you feel like you're falling.
|
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."
|
"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.
|
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.
|
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).
|
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:
|
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, 1
|
||||||
1, 6
|
1, 6
|
||||||
8, 3
|
8, 3
|
||||||
3, 4
|
3, 4
|
||||||
5, 5
|
5, 5
|
||||||
8, 9
|
8, 9
|
||||||
If we name these coordinates A through F, we can draw them on a grid, putting 0,0 at the top left:
|
If we name these coordinates A through F, we can draw them on a grid, putting 0,0 at the top left:
|
||||||
|
|
||||||
..........
|
..........
|
||||||
.A........
|
.A........
|
||||||
..........
|
..........
|
||||||
........C.
|
........C.
|
||||||
...D......
|
...D......
|
||||||
.....E....
|
.....E....
|
||||||
.B........
|
.B........
|
||||||
..........
|
..........
|
||||||
..........
|
..........
|
||||||
........F.
|
........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:
|
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
|
||||||
aAaaa.cccc
|
aAaaa.cccc
|
||||||
aaaddecccc
|
aaaddecccc
|
||||||
aadddeccCc
|
aadddeccCc
|
||||||
..dDdeeccc
|
..dDdeeccc
|
||||||
bb.deEeecc
|
bb.deEeecc
|
||||||
bBb.eeee..
|
bBb.eeee..
|
||||||
bbb.eeefff
|
bbb.eeefff
|
||||||
bbb.eeffff
|
bbb.eeffff
|
||||||
bbb.ffffFf
|
bbb.ffffFf
|
||||||
Locations shown as . are equally far from two or more coordinates, and so they don't count as being closest to any.
|
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.
|
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?
|
What is the size of the largest area that isn't infinite?
|
||||||
|
|
||||||
--- Part Two ---
|
--- 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.
|
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:
|
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........
|
.A........
|
||||||
..........
|
..........
|
||||||
...###..C.
|
...###..C.
|
||||||
..#D###...
|
..#D###...
|
||||||
..###E#...
|
..###E#...
|
||||||
.B.###....
|
.B.###....
|
||||||
..........
|
..........
|
||||||
..........
|
..........
|
||||||
........F.
|
........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:
|
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 A: abs(4-1) + abs(3-1) = 5
|
||||||
Distance to coordinate B: abs(4-1) + abs(3-6) = 6
|
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 C: abs(4-8) + abs(3-3) = 4
|
||||||
Distance to coordinate D: abs(4-3) + abs(3-4) = 2
|
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 E: abs(4-5) + abs(3-5) = 3
|
||||||
Distance to coordinate F: abs(4-8) + abs(3-9) = 10
|
Distance to coordinate F: abs(4-8) + abs(3-9) = 10
|
||||||
Total distance: 5 + 6 + 4 + 2 + 3 + 10 = 30
|
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.
|
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.
|
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.
|
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?
|
What is the size of the region containing all locations which have a total distance to all given coordinates of less than 10000?
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,50 @@
|
|||||||
194, 200
|
194, 200
|
||||||
299, 244
|
299, 244
|
||||||
269, 329
|
269, 329
|
||||||
292, 55
|
292, 55
|
||||||
211, 63
|
211, 63
|
||||||
123, 311
|
123, 311
|
||||||
212, 90
|
212, 90
|
||||||
292, 169
|
292, 169
|
||||||
359, 177
|
359, 177
|
||||||
354, 95
|
354, 95
|
||||||
101, 47
|
101, 47
|
||||||
95, 79
|
95, 79
|
||||||
95, 287
|
95, 287
|
||||||
294, 126
|
294, 126
|
||||||
81, 267
|
81, 267
|
||||||
330, 78
|
330, 78
|
||||||
202, 165
|
202, 165
|
||||||
225, 178
|
225, 178
|
||||||
266, 272
|
266, 272
|
||||||
351, 326
|
351, 326
|
||||||
180, 62
|
180, 62
|
||||||
102, 178
|
102, 178
|
||||||
151, 101
|
151, 101
|
||||||
343, 145
|
343, 145
|
||||||
205, 312
|
205, 312
|
||||||
74, 193
|
74, 193
|
||||||
221, 56
|
221, 56
|
||||||
89, 89
|
89, 89
|
||||||
242, 172
|
242, 172
|
||||||
59, 138
|
59, 138
|
||||||
83, 179
|
83, 179
|
||||||
223, 88
|
223, 88
|
||||||
297, 234
|
297, 234
|
||||||
147, 351
|
147, 351
|
||||||
226, 320
|
226, 320
|
||||||
358, 338
|
358, 338
|
||||||
321, 172
|
321, 172
|
||||||
54, 122
|
54, 122
|
||||||
263, 165
|
263, 165
|
||||||
126, 341
|
126, 341
|
||||||
64, 132
|
64, 132
|
||||||
264, 306
|
264, 306
|
||||||
72, 202
|
72, 202
|
||||||
98, 49
|
98, 49
|
||||||
238, 67
|
238, 67
|
||||||
310, 303
|
310, 303
|
||||||
277, 281
|
277, 281
|
||||||
222, 318
|
222, 318
|
||||||
357, 169
|
357, 169
|
||||||
123, 225
|
123, 225
|
||||||
@@ -1,131 +1,131 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
struct Point
|
struct Point
|
||||||
{
|
{
|
||||||
int64_t x, y;
|
int64_t x, y;
|
||||||
Point(const int64_t &X, const int64_t &Y) : x(X), y(Y) {}
|
Point(const int64_t &X, const int64_t &Y) : x(X), y(Y) {}
|
||||||
Point() = default;
|
Point() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
int64_t distance(const Point &a, const Point &b)
|
int64_t distance(const Point &a, const Point &b)
|
||||||
{
|
{
|
||||||
return std::abs(a.x - b.x) + std::abs(a.y - b.y);
|
return std::abs(a.x - b.x) + std::abs(a.y - b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream &operator>>(std::istream &is, Point &p)
|
std::istream &operator>>(std::istream &is, Point &p)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
is >> p.x >> c >> p.y;
|
is >> p.x >> c >> p.y;
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, Point &p)
|
std::ostream &operator<<(std::ostream &os, Point &p)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
os << p.x << ", " << p.y;
|
os << p.x << ", " << p.y;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t min_index(const size_t &invalid, const Point &point,
|
size_t min_index(const size_t &invalid, const Point &point,
|
||||||
const std::vector<Point> &points)
|
const std::vector<Point> &points)
|
||||||
{
|
{
|
||||||
size_t result;
|
size_t result;
|
||||||
int64_t min_dist(std::numeric_limits<int64_t>::max());
|
int64_t min_dist(std::numeric_limits<int64_t>::max());
|
||||||
for(size_t p = 0; p < points.size(); ++p)
|
for(size_t p = 0; p < points.size(); ++p)
|
||||||
{
|
{
|
||||||
int64_t d(distance(point, points[p]));
|
int64_t d(distance(point, points[p]));
|
||||||
if(min_dist > d)
|
if(min_dist > d)
|
||||||
{
|
{
|
||||||
min_dist = d;
|
min_dist = d;
|
||||||
result = p;
|
result = p;
|
||||||
}
|
}
|
||||||
else if(min_dist == d)
|
else if(min_dist == d)
|
||||||
{
|
{
|
||||||
result = invalid;
|
result = invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::ifstream infile(argv[1]);
|
std::ifstream infile(argv[1]);
|
||||||
std::vector<Point> points(std::istream_iterator<Point>(infile), {});
|
std::vector<Point> points(std::istream_iterator<Point>(infile), {});
|
||||||
|
|
||||||
int64_t min_x(std::numeric_limits<int64_t>::max()), min_y(min_x),
|
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);
|
max_x(std::numeric_limits<int64_t>::min()), max_y(max_x);
|
||||||
for(auto &p : points)
|
for(auto &p : points)
|
||||||
{
|
{
|
||||||
min_x = std::min(min_x, p.x);
|
min_x = std::min(min_x, p.x);
|
||||||
min_y = std::min(min_y, p.y);
|
min_y = std::min(min_y, p.y);
|
||||||
max_x = std::max(max_x, p.x);
|
max_x = std::max(max_x, p.x);
|
||||||
max_y = std::max(max_y, p.y);
|
max_y = std::max(max_y, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t width(max_x - min_x + 1), height(max_y - min_y + 1);
|
int64_t width(max_x - min_x + 1), height(max_y - min_y + 1);
|
||||||
const size_t invalid(points.size());
|
const size_t invalid(points.size());
|
||||||
std::vector<int64_t> num_claimed(points.size() + 1, 0);
|
std::vector<int64_t> num_claimed(points.size() + 1, 0);
|
||||||
std::set<size_t> invalid_points;
|
std::set<size_t> invalid_points;
|
||||||
|
|
||||||
for(int64_t x = min_x; x <= max_x; ++x)
|
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, min_y), points));
|
||||||
invalid_points.insert(min_index(invalid, Point(x, max_y), points));
|
invalid_points.insert(min_index(invalid, Point(x, max_y), points));
|
||||||
}
|
}
|
||||||
for(int64_t y = min_y; y <= max_y; ++y)
|
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(min_x, y), points));
|
||||||
invalid_points.insert(min_index(invalid, Point(max_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 x = 0; x < width; ++x)
|
||||||
for(int64_t y = 0; y < height; ++y)
|
for(int64_t y = 0; y < height; ++y)
|
||||||
{
|
{
|
||||||
int64_t min_dist(std::numeric_limits<int64_t>::max());
|
int64_t min_dist(std::numeric_limits<int64_t>::max());
|
||||||
size_t min_index;
|
size_t min_index;
|
||||||
for(size_t p = 0; p < points.size(); ++p)
|
for(size_t p = 0; p < points.size(); ++p)
|
||||||
{
|
{
|
||||||
int64_t d(distance(Point(x + min_x, y + min_y), points[p]));
|
int64_t d(distance(Point(x + min_x, y + min_y), points[p]));
|
||||||
if(min_dist > d)
|
if(min_dist > d)
|
||||||
{
|
{
|
||||||
min_dist = d;
|
min_dist = d;
|
||||||
min_index = p;
|
min_index = p;
|
||||||
}
|
}
|
||||||
else if(min_dist == d)
|
else if(min_dist == d)
|
||||||
{
|
{
|
||||||
min_index = invalid;
|
min_index = invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(invalid_points.find(min_index) == invalid_points.end())
|
if(invalid_points.find(min_index) == invalid_points.end())
|
||||||
++num_claimed[min_index];
|
++num_claimed[min_index];
|
||||||
}
|
}
|
||||||
std::cout << "Part 1: "
|
std::cout << "Part 1: "
|
||||||
<< *std::max_element(num_claimed.begin(), num_claimed.end())
|
<< *std::max_element(num_claimed.begin(), num_claimed.end())
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
int64_t area(0);
|
int64_t area(0);
|
||||||
constexpr int64_t cutoff(10000);
|
constexpr int64_t cutoff(10000);
|
||||||
const int64_t padding(cutoff / points.size() + 1);
|
const int64_t padding(cutoff / points.size() + 1);
|
||||||
|
|
||||||
const int64_t x_lower(min_x - padding), x_upper(max_x + 1 + padding),
|
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);
|
y_lower(min_y - padding), y_upper(max_y + 1 + padding);
|
||||||
for(int64_t x = x_lower; x < x_upper; ++x)
|
for(int64_t x = x_lower; x < x_upper; ++x)
|
||||||
for(int64_t y = y_lower; y < y_upper; ++y)
|
for(int64_t y = y_lower; y < y_upper; ++y)
|
||||||
{
|
{
|
||||||
int64_t total_dist(0);
|
int64_t total_dist(0);
|
||||||
for(auto &point : points)
|
for(auto &point : points)
|
||||||
{
|
{
|
||||||
total_dist += distance(Point(x, y), point);
|
total_dist += distance(Point(x, y), point);
|
||||||
if(total_dist > cutoff)
|
if(total_dist > cutoff)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(total_dist < cutoff)
|
if(total_dist < cutoff)
|
||||||
++area;
|
++area;
|
||||||
}
|
}
|
||||||
std::cout << "Part 2: " << area << "\n";
|
std::cout << "Part 2: " << area << "\n";
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,32 @@
|
|||||||
--- Day 1: The Tyranny of the Rocket Equation ---
|
--- Day 1: The Tyranny of the Rocket Equation ---
|
||||||
Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to Earth in time to save Christmas, he needs you to bring him measurements from fifty stars.
|
Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to Earth in time to save Christmas, he needs you to bring him measurements from fifty stars.
|
||||||
|
|
||||||
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!
|
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!
|
||||||
|
|
||||||
The Elves quickly load you into a spacecraft and prepare to launch.
|
The Elves quickly load you into a spacecraft and prepare to launch.
|
||||||
|
|
||||||
At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper. They haven't determined the amount of fuel required yet.
|
At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper. They haven't determined the amount of fuel required yet.
|
||||||
|
|
||||||
Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.
|
Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.
|
For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.
|
||||||
For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.
|
For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.
|
||||||
For a mass of 1969, the fuel required is 654.
|
For a mass of 1969, the fuel required is 654.
|
||||||
For a mass of 100756, the fuel required is 33583.
|
For a mass of 100756, the fuel required is 33583.
|
||||||
The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.
|
The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.
|
||||||
|
|
||||||
What is the sum of the fuel requirements for all of the modules on your spacecraft?
|
What is the sum of the fuel requirements for all of the modules on your spacecraft?
|
||||||
|
|
||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added.
|
During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added.
|
||||||
|
|
||||||
Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and subtract 2. However, that fuel also requires fuel, and that fuel requires fuel, and so on. Any mass that would require negative fuel should instead be treated as if it requires zero fuel; the remaining mass, if any, is instead handled by wishing really hard, which has no mass and is outside the scope of this calculation.
|
Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and subtract 2. However, that fuel also requires fuel, and that fuel requires fuel, and so on. Any mass that would require negative fuel should instead be treated as if it requires zero fuel; the remaining mass, if any, is instead handled by wishing really hard, which has no mass and is outside the scope of this calculation.
|
||||||
|
|
||||||
So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is zero or negative. For example:
|
So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is zero or negative. For example:
|
||||||
|
|
||||||
A module of mass 14 requires 2 fuel. This fuel requires no further fuel (2 divided by 3 and rounded down is 0, which would call for a negative fuel), so the total fuel required is still just 2.
|
A module of mass 14 requires 2 fuel. This fuel requires no further fuel (2 divided by 3 and rounded down is 0, which would call for a negative fuel), so the total fuel required is still just 2.
|
||||||
At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2). 216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel. So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966.
|
At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2). 216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel. So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966.
|
||||||
The fuel required by a module of mass 100756 and its fuel is: 33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346.
|
The fuel required by a module of mass 100756 and its fuel is: 33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346.
|
||||||
What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking into account the mass of the added fuel? (Calculate the fuel requirements for each module separately, then add them all up at the end.)
|
What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking into account the mass of the added fuel? (Calculate the fuel requirements for each module separately, then add them all up at the end.)
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
int accumilator = 0;
|
int accumilator = 0;
|
||||||
|
|
||||||
// for ( std::string line; !infile.eof(); std::getline( infile, line ) )
|
// for ( std::string line; !infile.eof(); std::getline( infile, line ) )
|
||||||
// {
|
// {
|
||||||
|
|
||||||
// if ( line.length() == 0 ) continue;
|
// if ( line.length() == 0 ) continue;
|
||||||
// accumilator += (std::stoi( line ) / 3) - 2;
|
// accumilator += (std::stoi( line ) / 3) - 2;
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (!infile.eof())
|
while (!infile.eof())
|
||||||
{
|
{
|
||||||
|
|
||||||
std::getline(infile, line);
|
std::getline(infile, line);
|
||||||
if ( line.length() == 0 ) continue;
|
if ( line.length() == 0 ) continue;
|
||||||
accumilator += (std::stoi( line ) / 3) - 2;
|
accumilator += (std::stoi( line ) / 3) - 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Sum of the fuel requrements : " << accumilator << std::endl;
|
std::cout << "Sum of the fuel requrements : " << accumilator << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
int fuelForMass ( int mass, int accumilator = 0 )
|
int fuelForMass ( int mass, int accumilator = 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
int res = (mass / 3) - 2;
|
int res = (mass / 3) - 2;
|
||||||
if ( res > 0 )
|
if ( res > 0 )
|
||||||
return fuelForMass( res, accumilator + res );
|
return fuelForMass( res, accumilator + res );
|
||||||
|
|
||||||
return accumilator;
|
return accumilator;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
int accumilator = 0;
|
int accumilator = 0;
|
||||||
|
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (!infile.eof())
|
while (!infile.eof())
|
||||||
{
|
{
|
||||||
|
|
||||||
std::getline(infile, line);
|
std::getline(infile, line);
|
||||||
if ( line.length() == 0 ) continue;
|
if ( line.length() == 0 ) continue;
|
||||||
accumilator += fuelForMass( std::stoi( line ) );
|
accumilator += fuelForMass( std::stoi( line ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Sum of the fuel requrements : " << accumilator << std::endl;
|
std::cout << "Sum of the fuel requrements : " << accumilator << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,100 +1,100 @@
|
|||||||
54755
|
54755
|
||||||
96495
|
96495
|
||||||
111504
|
111504
|
||||||
53923
|
53923
|
||||||
118158
|
118158
|
||||||
118082
|
118082
|
||||||
137413
|
137413
|
||||||
135315
|
135315
|
||||||
87248
|
87248
|
||||||
127646
|
127646
|
||||||
79201
|
79201
|
||||||
52399
|
52399
|
||||||
77966
|
77966
|
||||||
129568
|
129568
|
||||||
63880
|
63880
|
||||||
128973
|
128973
|
||||||
55491
|
55491
|
||||||
111226
|
111226
|
||||||
126447
|
126447
|
||||||
87017
|
87017
|
||||||
112469
|
112469
|
||||||
83975
|
83975
|
||||||
51280
|
51280
|
||||||
60239
|
60239
|
||||||
120524
|
120524
|
||||||
57122
|
57122
|
||||||
136517
|
136517
|
||||||
117378
|
117378
|
||||||
93629
|
93629
|
||||||
55125
|
55125
|
||||||
68990
|
68990
|
||||||
70336
|
70336
|
||||||
115119
|
115119
|
||||||
68264
|
68264
|
||||||
148122
|
148122
|
||||||
70075
|
70075
|
||||||
106770
|
106770
|
||||||
54976
|
54976
|
||||||
123852
|
123852
|
||||||
61813
|
61813
|
||||||
113373
|
113373
|
||||||
53924
|
53924
|
||||||
59660
|
59660
|
||||||
67111
|
67111
|
||||||
52825
|
52825
|
||||||
81568
|
81568
|
||||||
110842
|
110842
|
||||||
134870
|
134870
|
||||||
135529
|
135529
|
||||||
78689
|
78689
|
||||||
129451
|
129451
|
||||||
96041
|
96041
|
||||||
91627
|
91627
|
||||||
70863
|
70863
|
||||||
100098
|
100098
|
||||||
121908
|
121908
|
||||||
96623
|
96623
|
||||||
143752
|
143752
|
||||||
149936
|
149936
|
||||||
116283
|
116283
|
||||||
149488
|
149488
|
||||||
126158
|
126158
|
||||||
106499
|
106499
|
||||||
124927
|
124927
|
||||||
109574
|
109574
|
||||||
70711
|
70711
|
||||||
139078
|
139078
|
||||||
67212
|
67212
|
||||||
124251
|
124251
|
||||||
123803
|
123803
|
||||||
73569
|
73569
|
||||||
145668
|
145668
|
||||||
96045
|
96045
|
||||||
59748
|
59748
|
||||||
123238
|
123238
|
||||||
68005
|
68005
|
||||||
121412
|
121412
|
||||||
97236
|
97236
|
||||||
104800
|
104800
|
||||||
86786
|
86786
|
||||||
141680
|
141680
|
||||||
123807
|
123807
|
||||||
82310
|
82310
|
||||||
76593
|
76593
|
||||||
146092
|
146092
|
||||||
82637
|
82637
|
||||||
92339
|
92339
|
||||||
93821
|
93821
|
||||||
56247
|
56247
|
||||||
58328
|
58328
|
||||||
90159
|
90159
|
||||||
105700
|
105700
|
||||||
57317
|
57317
|
||||||
69011
|
69011
|
||||||
125544
|
125544
|
||||||
102372
|
102372
|
||||||
63797
|
63797
|
||||||
92127
|
92127
|
||||||
111207
|
111207
|
||||||
77596
|
77596
|
||||||
@@ -1,64 +1,64 @@
|
|||||||
--- Day 2: 1202 Program Alarm ---
|
--- Day 2: 1202 Program Alarm ---
|
||||||
On the way to your gravity assist around the Moon, your ship computer beeps angrily about a "1202 program alarm". On the radio, an Elf is already explaining how to handle the situation: "Don't worry, that's perfectly norma--" The ship computer bursts into flames.
|
On the way to your gravity assist around the Moon, your ship computer beeps angrily about a "1202 program alarm". On the radio, an Elf is already explaining how to handle the situation: "Don't worry, that's perfectly norma--" The ship computer bursts into flames.
|
||||||
|
|
||||||
You notify the Elves that the computer's magic smoke seems to have escaped. "That computer ran Intcode programs like the gravity assist program it was working on; surely there are enough spare parts up there to build a new Intcode computer!"
|
You notify the Elves that the computer's magic smoke seems to have escaped. "That computer ran Intcode programs like the gravity assist program it was working on; surely there are enough spare parts up there to build a new Intcode computer!"
|
||||||
|
|
||||||
An Intcode program is a list of integers separated by commas (like 1,0,0,3,99). To run one, start by looking at the first integer (called position 0). Here, you will find an opcode - either 1, 2, or 99. The opcode indicates what to do; for example, 99 means that the program is finished and should immediately halt. Encountering an unknown opcode means something went wrong.
|
An Intcode program is a list of integers separated by commas (like 1,0,0,3,99). To run one, start by looking at the first integer (called position 0). Here, you will find an opcode - either 1, 2, or 99. The opcode indicates what to do; for example, 99 means that the program is finished and should immediately halt. Encountering an unknown opcode means something went wrong.
|
||||||
|
|
||||||
Opcode 1 adds together numbers read from two positions and stores the result in a third position. The three integers immediately after the opcode tell you these three positions - the first two indicate the positions from which you should read the input values, and the third indicates the position at which the output should be stored.
|
Opcode 1 adds together numbers read from two positions and stores the result in a third position. The three integers immediately after the opcode tell you these three positions - the first two indicate the positions from which you should read the input values, and the third indicates the position at which the output should be stored.
|
||||||
|
|
||||||
For example, if your Intcode computer encounters 1,10,20,30, it should read the values at positions 10 and 20, add those values, and then overwrite the value at position 30 with their sum.
|
For example, if your Intcode computer encounters 1,10,20,30, it should read the values at positions 10 and 20, add those values, and then overwrite the value at position 30 with their sum.
|
||||||
|
|
||||||
Opcode 2 works exactly like opcode 1, except it multiplies the two inputs instead of adding them. Again, the three integers after the opcode indicate where the inputs and outputs are, not their values.
|
Opcode 2 works exactly like opcode 1, except it multiplies the two inputs instead of adding them. Again, the three integers after the opcode indicate where the inputs and outputs are, not their values.
|
||||||
|
|
||||||
Once you're done processing an opcode, move to the next one by stepping forward 4 positions.
|
Once you're done processing an opcode, move to the next one by stepping forward 4 positions.
|
||||||
|
|
||||||
For example, suppose you have the following program:
|
For example, suppose you have the following program:
|
||||||
|
|
||||||
1,9,10,3,2,3,11,0,99,30,40,50
|
1,9,10,3,2,3,11,0,99,30,40,50
|
||||||
For the purposes of illustration, here is the same program split into multiple lines:
|
For the purposes of illustration, here is the same program split into multiple lines:
|
||||||
|
|
||||||
1,9,10,3,
|
1,9,10,3,
|
||||||
2,3,11,0,
|
2,3,11,0,
|
||||||
99,
|
99,
|
||||||
30,40,50
|
30,40,50
|
||||||
The first four integers, 1,9,10,3, are at positions 0, 1, 2, and 3. Together, they represent the first opcode (1, addition), the positions of the two inputs (9 and 10), and the position of the output (3). To handle this opcode, you first need to get the values at the input positions: position 9 contains 30, and position 10 contains 40. Add these numbers together to get 70. Then, store this value at the output position; here, the output position (3) is at position 3, so it overwrites itself. Afterward, the program looks like this:
|
The first four integers, 1,9,10,3, are at positions 0, 1, 2, and 3. Together, they represent the first opcode (1, addition), the positions of the two inputs (9 and 10), and the position of the output (3). To handle this opcode, you first need to get the values at the input positions: position 9 contains 30, and position 10 contains 40. Add these numbers together to get 70. Then, store this value at the output position; here, the output position (3) is at position 3, so it overwrites itself. Afterward, the program looks like this:
|
||||||
|
|
||||||
1,9,10,70,
|
1,9,10,70,
|
||||||
2,3,11,0,
|
2,3,11,0,
|
||||||
99,
|
99,
|
||||||
30,40,50
|
30,40,50
|
||||||
Step forward 4 positions to reach the next opcode, 2. This opcode works just like the previous, but it multiplies instead of adding. The inputs are at positions 3 and 11; these positions contain 70 and 50 respectively. Multiplying these produces 3500; this is stored at position 0:
|
Step forward 4 positions to reach the next opcode, 2. This opcode works just like the previous, but it multiplies instead of adding. The inputs are at positions 3 and 11; these positions contain 70 and 50 respectively. Multiplying these produces 3500; this is stored at position 0:
|
||||||
|
|
||||||
3500,9,10,70,
|
3500,9,10,70,
|
||||||
2,3,11,0,
|
2,3,11,0,
|
||||||
99,
|
99,
|
||||||
30,40,50
|
30,40,50
|
||||||
Stepping forward 4 more positions arrives at opcode 99, halting the program.
|
Stepping forward 4 more positions arrives at opcode 99, halting the program.
|
||||||
|
|
||||||
Here are the initial and final states of a few more small programs:
|
Here are the initial and final states of a few more small programs:
|
||||||
|
|
||||||
1,0,0,0,99 becomes 2,0,0,0,99 (1 + 1 = 2).
|
1,0,0,0,99 becomes 2,0,0,0,99 (1 + 1 = 2).
|
||||||
2,3,0,3,99 becomes 2,3,0,6,99 (3 * 2 = 6).
|
2,3,0,3,99 becomes 2,3,0,6,99 (3 * 2 = 6).
|
||||||
2,4,4,5,99,0 becomes 2,4,4,5,99,9801 (99 * 99 = 9801).
|
2,4,4,5,99,0 becomes 2,4,4,5,99,9801 (99 * 99 = 9801).
|
||||||
1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99.
|
1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99.
|
||||||
Once you have a working computer, the first step is to restore the gravity assist program (your puzzle input) to the "1202 program alarm" state it had just before the last computer caught fire. To do this, before running the program, replace position 1 with the value 12 and replace position 2 with the value 2. What value is left at position 0 after the program halts?
|
Once you have a working computer, the first step is to restore the gravity assist program (your puzzle input) to the "1202 program alarm" state it had just before the last computer caught fire. To do this, before running the program, replace position 1 with the value 12 and replace position 2 with the value 2. What value is left at position 0 after the program halts?
|
||||||
|
|
||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
"Good, the new computer seems to be working correctly! Keep it nearby during this mission - you'll probably use it again. Real Intcode computers support many more features than your new one, but we'll let you know what they are as you need them."
|
"Good, the new computer seems to be working correctly! Keep it nearby during this mission - you'll probably use it again. Real Intcode computers support many more features than your new one, but we'll let you know what they are as you need them."
|
||||||
|
|
||||||
"However, your current priority should be to complete your gravity assist around the Moon. For this mission to succeed, we should settle on some terminology for the parts you've already built."
|
"However, your current priority should be to complete your gravity assist around the Moon. For this mission to succeed, we should settle on some terminology for the parts you've already built."
|
||||||
|
|
||||||
Intcode programs are given as a list of integers; these values are used as the initial state for the computer's memory. When you run an Intcode program, make sure to start by initializing memory to the program's values. A position in memory is called an address (for example, the first value in memory is at "address 0").
|
Intcode programs are given as a list of integers; these values are used as the initial state for the computer's memory. When you run an Intcode program, make sure to start by initializing memory to the program's values. A position in memory is called an address (for example, the first value in memory is at "address 0").
|
||||||
|
|
||||||
Opcodes (like 1, 2, or 99) mark the beginning of an instruction. The values used immediately after an opcode, if any, are called the instruction's parameters. For example, in the instruction 1,2,3,4, 1 is the opcode; 2, 3, and 4 are the parameters. The instruction 99 contains only an opcode and has no parameters.
|
Opcodes (like 1, 2, or 99) mark the beginning of an instruction. The values used immediately after an opcode, if any, are called the instruction's parameters. For example, in the instruction 1,2,3,4, 1 is the opcode; 2, 3, and 4 are the parameters. The instruction 99 contains only an opcode and has no parameters.
|
||||||
|
|
||||||
The address of the current instruction is called the instruction pointer; it starts at 0. After an instruction finishes, the instruction pointer increases by the number of values in the instruction; until you add more instructions to the computer, this is always 4 (1 opcode + 3 parameters) for the add and multiply instructions. (The halt instruction would increase the instruction pointer by 1, but it halts the program instead.)
|
The address of the current instruction is called the instruction pointer; it starts at 0. After an instruction finishes, the instruction pointer increases by the number of values in the instruction; until you add more instructions to the computer, this is always 4 (1 opcode + 3 parameters) for the add and multiply instructions. (The halt instruction would increase the instruction pointer by 1, but it halts the program instead.)
|
||||||
|
|
||||||
"With terminology out of the way, we're ready to proceed. To complete the gravity assist, you need to determine what pair of inputs produces the output 19690720."
|
"With terminology out of the way, we're ready to proceed. To complete the gravity assist, you need to determine what pair of inputs produces the output 19690720."
|
||||||
|
|
||||||
The inputs should still be provided to the program by replacing the values at addresses 1 and 2, just like before. In this program, the value placed in address 1 is called the noun, and the value placed in address 2 is called the verb. Each of the two input values will be between 0 and 99, inclusive.
|
The inputs should still be provided to the program by replacing the values at addresses 1 and 2, just like before. In this program, the value placed in address 1 is called the noun, and the value placed in address 2 is called the verb. Each of the two input values will be between 0 and 99, inclusive.
|
||||||
|
|
||||||
Once the program has halted, its output is available at address 0, also just like before. Each time you try a pair of inputs, make sure you first reset the computer's memory to the values in the program (your puzzle input) - in other words, don't reuse memory from a previous attempt.
|
Once the program has halted, its output is available at address 0, also just like before. Each time you try a pair of inputs, make sure you first reset the computer's memory to the values in the program (your puzzle input) - in other words, don't reuse memory from a previous attempt.
|
||||||
|
|
||||||
Find the input noun and verb that cause the program to produce the output 19690720. What is 100 * noun + verb? (For example, if noun=12 and verb=2, the answer would be 1202.)
|
Find the input noun and verb that cause the program to produce the output 19690720. What is 100 * noun + verb? (For example, if noun=12 and verb=2, the answer would be 1202.)
|
||||||
|
|||||||
@@ -1,79 +1,79 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<int> tokenise( std::string input )
|
std::vector<int> tokenise( std::string input )
|
||||||
{
|
{
|
||||||
std::stringstream ssInput( input );
|
std::stringstream ssInput( input );
|
||||||
std::vector<int> stream;
|
std::vector<int> stream;
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
while( std::getline( ssInput, s, ',' ) ) {
|
while( std::getline( ssInput, s, ',' ) ) {
|
||||||
stream.push_back( std::stoi( s ) );
|
stream.push_back( std::stoi( s ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Opcodes
|
enum Opcodes
|
||||||
{
|
{
|
||||||
Add = 1,
|
Add = 1,
|
||||||
Multiply = 2,
|
Multiply = 2,
|
||||||
End = 99
|
End = 99
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
|
|
||||||
std::vector<int> program = tokenise( input );
|
std::vector<int> program = tokenise( input );
|
||||||
|
|
||||||
program[1] = 12;
|
program[1] = 12;
|
||||||
program[2] = 2;
|
program[2] = 2;
|
||||||
|
|
||||||
for ( int i = 0; i < program.size(); i += 4 )
|
for ( int i = 0; i < program.size(); i += 4 )
|
||||||
{
|
{
|
||||||
|
|
||||||
int opcode = program[i];
|
int opcode = program[i];
|
||||||
|
|
||||||
std::cout << "Opcode : " << opcode << std::endl;
|
std::cout << "Opcode : " << opcode << std::endl;
|
||||||
|
|
||||||
int operandLocA = program[i + 1];
|
int operandLocA = program[i + 1];
|
||||||
int operandLocB = program[i + 2];
|
int operandLocB = program[i + 2];
|
||||||
|
|
||||||
std::cout << "Operand locations : " << operandLocA << ", " << operandLocB << std::endl;
|
std::cout << "Operand locations : " << operandLocA << ", " << operandLocB << std::endl;
|
||||||
|
|
||||||
int operandA = program[operandLocA];
|
int operandA = program[operandLocA];
|
||||||
int operandB = program[operandLocB];
|
int operandB = program[operandLocB];
|
||||||
|
|
||||||
int resLoc = program[i + 3];
|
int resLoc = program[i + 3];
|
||||||
|
|
||||||
std::cout << "Result location : " << resLoc << std::endl;
|
std::cout << "Result location : " << resLoc << std::endl;
|
||||||
|
|
||||||
if ( opcode == Add )
|
if ( opcode == Add )
|
||||||
program[resLoc] = operandA + operandB;
|
program[resLoc] = operandA + operandB;
|
||||||
else if ( opcode == Multiply )
|
else if ( opcode == Multiply )
|
||||||
program[resLoc] = operandA * operandB;
|
program[resLoc] = operandA * operandB;
|
||||||
else if ( opcode == End )
|
else if ( opcode == End )
|
||||||
{
|
{
|
||||||
std::cout << "Program end" << std::endl << std::endl;
|
std::cout << "Program end" << std::endl << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Program end state : ";
|
std::cout << "Program end state : ";
|
||||||
for ( auto& i : program )
|
for ( auto& i : program )
|
||||||
std::cout << i << " ";
|
std::cout << i << " ";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +1,81 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<int> tokenise( std::string input )
|
std::vector<int> tokenise( std::string input )
|
||||||
{
|
{
|
||||||
std::stringstream ssInput( input );
|
std::stringstream ssInput( input );
|
||||||
std::vector<int> stream;
|
std::vector<int> stream;
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
while( std::getline( ssInput, s, ',' ) )
|
while( std::getline( ssInput, s, ',' ) )
|
||||||
{
|
{
|
||||||
stream.push_back( std::stoi( s ) );
|
stream.push_back( std::stoi( s ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Opcodes
|
enum Opcodes
|
||||||
{
|
{
|
||||||
Add = 1,
|
Add = 1,
|
||||||
Multiply = 2,
|
Multiply = 2,
|
||||||
End = 99
|
End = 99
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
|
|
||||||
std::vector<int> program;
|
std::vector<int> program;
|
||||||
|
|
||||||
for ( int noun = 0; noun < 100; noun++ )
|
for ( int noun = 0; noun < 100; noun++ )
|
||||||
for ( int verb = 0; verb < 100; verb++ )
|
for ( int verb = 0; verb < 100; verb++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
program = tokenise( input );
|
program = tokenise( input );
|
||||||
|
|
||||||
// Noun
|
// Noun
|
||||||
program[1] = noun;
|
program[1] = noun;
|
||||||
// Verb
|
// Verb
|
||||||
program[2] = verb;
|
program[2] = verb;
|
||||||
|
|
||||||
for ( int i = 0; i < program.size(); i += 4 )
|
for ( int i = 0; i < program.size(); i += 4 )
|
||||||
{
|
{
|
||||||
|
|
||||||
int opcode = program[i];
|
int opcode = program[i];
|
||||||
|
|
||||||
int operandA = program[program[i + 1]];
|
int operandA = program[program[i + 1]];
|
||||||
int operandB = program[program[i + 2]];
|
int operandB = program[program[i + 2]];
|
||||||
|
|
||||||
int resLoc = program[i + 3];
|
int resLoc = program[i + 3];
|
||||||
|
|
||||||
if ( opcode == Add )
|
if ( opcode == Add )
|
||||||
program[resLoc] = operandA + operandB;
|
program[resLoc] = operandA + operandB;
|
||||||
else if ( opcode == Multiply )
|
else if ( opcode == Multiply )
|
||||||
program[resLoc] = operandA * operandB;
|
program[resLoc] = operandA * operandB;
|
||||||
else if ( opcode == End )
|
else if ( opcode == End )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( program[0] == 19690720 )
|
if ( program[0] == 19690720 )
|
||||||
{
|
{
|
||||||
std::cout << "Solution found : " << noun << " " << verb << std::endl;
|
std::cout << "Solution found : " << noun << " " << verb << std::endl;
|
||||||
std::cout << "Solution answer : " << 100 * noun + verb << std::endl;
|
std::cout << "Solution answer : " << 100 * noun + verb << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl << "Program end state : ";
|
std::cout << std::endl << "Program end state : ";
|
||||||
for ( auto& i : program )
|
for ( auto& i : program )
|
||||||
std::cout << i << " ";
|
std::cout << i << " ";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +1,70 @@
|
|||||||
--- Day 3: Crossed Wires ---
|
--- Day 3: Crossed Wires ---
|
||||||
The gravity assist was successful, and you're well on your way to the Venus refuelling station. During the rush back on Earth, the fuel management system wasn't completely installed, so that's next on the priority list.
|
The gravity assist was successful, and you're well on your way to the Venus refuelling station. During the rush back on Earth, the fuel management system wasn't completely installed, so that's next on the priority list.
|
||||||
|
|
||||||
Opening the front panel reveals a jumble of wires. Specifically, two wires are connected to a central port and extend outward on a grid. You trace the path each wire takes as it leaves the central port, one wire per line of text (your puzzle input).
|
Opening the front panel reveals a jumble of wires. Specifically, two wires are connected to a central port and extend outward on a grid. You trace the path each wire takes as it leaves the central port, one wire per line of text (your puzzle input).
|
||||||
|
|
||||||
The wires twist and turn, but the two wires occasionally cross paths. To fix the circuit, you need to find the intersection point closest to the central port. Because the wires are on a grid, use the Manhattan distance for this measurement. While the wires do technically cross right at the central port where they both start, this point does not count, nor does a wire count as crossing with itself.
|
The wires twist and turn, but the two wires occasionally cross paths. To fix the circuit, you need to find the intersection point closest to the central port. Because the wires are on a grid, use the Manhattan distance for this measurement. While the wires do technically cross right at the central port where they both start, this point does not count, nor does a wire count as crossing with itself.
|
||||||
|
|
||||||
For example, if the first wire's path is R8,U5,L5,D3, then starting from the central port (o), it goes right 8, up 5, left 5, and finally down 3:
|
For example, if the first wire's path is R8,U5,L5,D3, then starting from the central port (o), it goes right 8, up 5, left 5, and finally down 3:
|
||||||
|
|
||||||
...........
|
...........
|
||||||
...........
|
...........
|
||||||
...........
|
...........
|
||||||
....+----+.
|
....+----+.
|
||||||
....|....|.
|
....|....|.
|
||||||
....|....|.
|
....|....|.
|
||||||
....|....|.
|
....|....|.
|
||||||
.........|.
|
.........|.
|
||||||
.o-------+.
|
.o-------+.
|
||||||
...........
|
...........
|
||||||
Then, if the second wire's path is U7,R6,D4,L4, it goes up 7, right 6, down 4, and left 4:
|
Then, if the second wire's path is U7,R6,D4,L4, it goes up 7, right 6, down 4, and left 4:
|
||||||
|
|
||||||
...........
|
...........
|
||||||
.+-----+...
|
.+-----+...
|
||||||
.|.....|...
|
.|.....|...
|
||||||
.|..+--X-+.
|
.|..+--X-+.
|
||||||
.|..|..|.|.
|
.|..|..|.|.
|
||||||
.|.-X--+.|.
|
.|.-X--+.|.
|
||||||
.|..|....|.
|
.|..|....|.
|
||||||
.|.......|.
|
.|.......|.
|
||||||
.o-------+.
|
.o-------+.
|
||||||
...........
|
...........
|
||||||
These wires cross at two locations (marked X), but the lower-left one is closer to the central port: its distance is 3 + 3 = 6.
|
These wires cross at two locations (marked X), but the lower-left one is closer to the central port: its distance is 3 + 3 = 6.
|
||||||
|
|
||||||
Here are a few more examples:
|
Here are a few more examples:
|
||||||
|
|
||||||
R75,D30,R83,U83,L12,D49,R71,U7,L72
|
R75,D30,R83,U83,L12,D49,R71,U7,L72
|
||||||
U62,R66,U55,R34,D71,R55,D58,R83 = distance 159
|
U62,R66,U55,R34,D71,R55,D58,R83 = distance 159
|
||||||
R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
|
R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
|
||||||
U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = distance 135
|
U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = distance 135
|
||||||
|
|
||||||
What is the Manhattan distance from the central port to the closest intersection?
|
What is the Manhattan distance from the central port to the closest intersection?
|
||||||
|
|
||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
It turns out that this circuit is very timing-sensitive; you actually need to minimize the signal delay.
|
It turns out that this circuit is very timing-sensitive; you actually need to minimize the signal delay.
|
||||||
|
|
||||||
To do this, calculate the number of steps each wire takes to reach each intersection; choose the intersection where the sum of both wires' steps is lowest. If a wire visits a position on the grid multiple times, use the steps value from the first time it visits that position when calculating the total value of a specific intersection.
|
To do this, calculate the number of steps each wire takes to reach each intersection; choose the intersection where the sum of both wires' steps is lowest. If a wire visits a position on the grid multiple times, use the steps value from the first time it visits that position when calculating the total value of a specific intersection.
|
||||||
|
|
||||||
The number of steps a wire takes is the total number of grid squares the wire has entered to get to that location, including the intersection being considered. Again consider the example from above:
|
The number of steps a wire takes is the total number of grid squares the wire has entered to get to that location, including the intersection being considered. Again consider the example from above:
|
||||||
|
|
||||||
...........
|
...........
|
||||||
.+-----+...
|
.+-----+...
|
||||||
.|.....|...
|
.|.....|...
|
||||||
.|..+--X-+.
|
.|..+--X-+.
|
||||||
.|..|..|.|.
|
.|..|..|.|.
|
||||||
.|.-X--+.|.
|
.|.-X--+.|.
|
||||||
.|..|....|.
|
.|..|....|.
|
||||||
.|.......|.
|
.|.......|.
|
||||||
.o-------+.
|
.o-------+.
|
||||||
...........
|
...........
|
||||||
In the above example, the intersection closest to the central port is reached after 8+5+5+2 = 20 steps by the first wire and 7+6+4+3 = 20 steps by the second wire for a total of 20+20 = 40 steps.
|
In the above example, the intersection closest to the central port is reached after 8+5+5+2 = 20 steps by the first wire and 7+6+4+3 = 20 steps by the second wire for a total of 20+20 = 40 steps.
|
||||||
|
|
||||||
However, the top-right intersection is better: the first wire takes only 8+5+2 = 15 and the second wire takes only 7+6+2 = 15, a total of 15+15 = 30 steps.
|
However, the top-right intersection is better: the first wire takes only 8+5+2 = 15 and the second wire takes only 7+6+2 = 15, a total of 15+15 = 30 steps.
|
||||||
|
|
||||||
Here are the best steps for the extra examples from above:
|
Here are the best steps for the extra examples from above:
|
||||||
|
|
||||||
R75,D30,R83,U83,L12,D49,R71,U7,L72
|
R75,D30,R83,U83,L12,D49,R71,U7,L72
|
||||||
U62,R66,U55,R34,D71,R55,D58,R83 = 610 steps
|
U62,R66,U55,R34,D71,R55,D58,R83 = 610 steps
|
||||||
R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
|
R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
|
||||||
U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = 410 steps
|
U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = 410 steps
|
||||||
What is the fewest combined steps the wires must take to reach an intersection?
|
What is the fewest combined steps the wires must take to reach an intersection?
|
||||||
|
|||||||
@@ -1,154 +1,154 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
std::vector<std::string> tokenise( std::string input )
|
std::vector<std::string> tokenise( std::string input )
|
||||||
{
|
{
|
||||||
std::stringstream ssInput( input );
|
std::stringstream ssInput( input );
|
||||||
std::vector<std::string> stream;
|
std::vector<std::string> stream;
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
while( std::getline( ssInput, s, ',' ) ) {
|
while( std::getline( ssInput, s, ',' ) ) {
|
||||||
stream.push_back( s );
|
stream.push_back( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vec2
|
struct vec2
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
bool operator==(const vec2& v) const
|
bool operator==(const vec2& v) const
|
||||||
{
|
{
|
||||||
return x == v.x && y == v.y;
|
return x == v.x && y == v.y;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
template <>
|
template <>
|
||||||
struct hash<vec2>
|
struct hash<vec2>
|
||||||
{
|
{
|
||||||
size_t operator()( const vec2& v ) const
|
size_t operator()( const vec2& v ) const
|
||||||
{
|
{
|
||||||
return v.x ^ v.y;
|
return v.x ^ v.y;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Wire
|
struct Wire
|
||||||
{
|
{
|
||||||
vec2 Head = { 0, 0 };
|
vec2 Head = { 0, 0 };
|
||||||
vec2 Origin = { 0, 0 };
|
vec2 Origin = { 0, 0 };
|
||||||
std::vector<vec2> Visited;
|
std::vector<vec2> Visited;
|
||||||
};
|
};
|
||||||
|
|
||||||
void step( std::vector<vec2>& path, vec2& pos, int steps, char dir )
|
void step( std::vector<vec2>& path, vec2& pos, int steps, char dir )
|
||||||
{
|
{
|
||||||
|
|
||||||
auto up = []( vec2& p ) { p.y -= 1; };
|
auto up = []( vec2& p ) { p.y -= 1; };
|
||||||
auto down = []( vec2& p ) { p.y += 1; };
|
auto down = []( vec2& p ) { p.y += 1; };
|
||||||
auto left = []( vec2& p ) { p.x -= 1; };
|
auto left = []( vec2& p ) { p.x -= 1; };
|
||||||
auto right = []( vec2& p ) { p.x += 1; };
|
auto right = []( vec2& p ) { p.x += 1; };
|
||||||
|
|
||||||
void (*stepSingle)(vec2&);
|
void (*stepSingle)(vec2&);
|
||||||
|
|
||||||
switch ( dir )
|
switch ( dir )
|
||||||
{
|
{
|
||||||
case 'U': stepSingle = up; break;
|
case 'U': stepSingle = up; break;
|
||||||
case 'D': stepSingle = down; break;
|
case 'D': stepSingle = down; break;
|
||||||
case 'R': stepSingle = right; break;
|
case 'R': stepSingle = right; break;
|
||||||
case 'L': stepSingle = left; break;
|
case 'L': stepSingle = left; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < steps; i++ )
|
for( int i = 0; i < steps; i++ )
|
||||||
{
|
{
|
||||||
stepSingle( pos );
|
stepSingle( pos );
|
||||||
path.push_back( pos );
|
path.push_back( pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
std::vector<std::string> wireS1 = tokenise( input );
|
std::vector<std::string> wireS1 = tokenise( input );
|
||||||
|
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
std::vector<std::string> wireS2 = tokenise( input );
|
std::vector<std::string> wireS2 = tokenise( input );
|
||||||
|
|
||||||
// Construct map of nodes
|
// Construct map of nodes
|
||||||
// for each point a wire
|
// for each point a wire
|
||||||
// lays on, one is added
|
// lays on, one is added
|
||||||
// to the node
|
// to the node
|
||||||
|
|
||||||
// Wires are assumed to start at 0,0
|
// Wires are assumed to start at 0,0
|
||||||
|
|
||||||
Wire wire1;
|
Wire wire1;
|
||||||
for ( auto& element : wireS1 )
|
for ( auto& element : wireS1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Seperate the direction from the displacement
|
// Seperate the direction from the displacement
|
||||||
|
|
||||||
char direction = element[0];
|
char direction = element[0];
|
||||||
int displacement = std::stoi( element.substr( 1, element.size() ) );
|
int displacement = std::stoi( element.substr( 1, element.size() ) );
|
||||||
|
|
||||||
step(wire1.Visited, wire1.Head, displacement, direction);
|
step(wire1.Visited, wire1.Head, displacement, direction);
|
||||||
|
|
||||||
std::cout << "Wire 1 " << element << std::endl;
|
std::cout << "Wire 1 " << element << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire wire2;
|
Wire wire2;
|
||||||
for ( auto& element : wireS2 )
|
for ( auto& element : wireS2 )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Seperate the direction from the displacement
|
// Seperate the direction from the displacement
|
||||||
|
|
||||||
char direction = element[0];
|
char direction = element[0];
|
||||||
int displacement = std::stoi( element.substr( 1, element.size() ) );
|
int displacement = std::stoi( element.substr( 1, element.size() ) );
|
||||||
|
|
||||||
step(wire2.Visited, wire2.Head, displacement, direction);
|
step(wire2.Visited, wire2.Head, displacement, direction);
|
||||||
|
|
||||||
std::cout << "Wire 2 " << element << std::endl;
|
std::cout << "Wire 2 " << element << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto find = []( std::vector<vec2> arr, vec2 el ) {
|
auto find = []( std::vector<vec2> arr, vec2 el ) {
|
||||||
for ( int i = 0; i < arr.size(); i++ )
|
for ( int i = 0; i < arr.size(); i++ )
|
||||||
if ( arr[i] == el ) return i;
|
if ( arr[i] == el ) return i;
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<int> intersectDistances;
|
std::vector<int> intersectDistances;
|
||||||
|
|
||||||
// This takes a good few seconds
|
// This takes a good few seconds
|
||||||
for ( int i = 0; i < wire1.Visited.size(); i++ )
|
for ( int i = 0; i < wire1.Visited.size(); i++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
vec2 v = wire1.Visited[i];
|
vec2 v = wire1.Visited[i];
|
||||||
if ( find( wire2.Visited, v ) != -1 )
|
if ( find( wire2.Visited, v ) != -1 )
|
||||||
{
|
{
|
||||||
std::cout << "Found : " << v.x << " " << v.y << std::endl;
|
std::cout << "Found : " << v.x << " " << v.y << std::endl;
|
||||||
intersectDistances.push_back( std::abs( v.x ) + std::abs( v.y ) );
|
intersectDistances.push_back( std::abs( v.x ) + std::abs( v.y ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int minDistance = *std::min_element( intersectDistances.cbegin(), intersectDistances.cend() );
|
int minDistance = *std::min_element( intersectDistances.cbegin(), intersectDistances.cend() );
|
||||||
|
|
||||||
std::cout << "Minimum Distance to Intersect : " << minDistance << std::endl;
|
std::cout << "Minimum Distance to Intersect : " << minDistance << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,116 +1,116 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
std::vector<std::string> tokenise( std::string input )
|
std::vector<std::string> tokenise( std::string input )
|
||||||
{
|
{
|
||||||
std::stringstream ssInput( input );
|
std::stringstream ssInput( input );
|
||||||
std::vector<std::string> stream;
|
std::vector<std::string> stream;
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
while( std::getline( ssInput, s, ',' ) ) {
|
while( std::getline( ssInput, s, ',' ) ) {
|
||||||
stream.push_back( s );
|
stream.push_back( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vec2
|
struct vec2
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
bool operator==(const vec2& v) const
|
bool operator==(const vec2& v) const
|
||||||
{
|
{
|
||||||
return x == v.x && y == v.y;
|
return x == v.x && y == v.y;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
template <>
|
template <>
|
||||||
struct hash<vec2>
|
struct hash<vec2>
|
||||||
{
|
{
|
||||||
size_t operator()( const vec2& v ) const
|
size_t operator()( const vec2& v ) const
|
||||||
{
|
{
|
||||||
return v.x ^ v.y;
|
return v.x ^ v.y;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<vec2, int> genPath( std::vector<std::string> wire )
|
std::unordered_map<vec2, int> genPath( std::vector<std::string> wire )
|
||||||
{
|
{
|
||||||
std::unordered_map<vec2, int> path;
|
std::unordered_map<vec2, int> path;
|
||||||
vec2 pos = { 0, 0 };
|
vec2 pos = { 0, 0 };
|
||||||
path[pos] = 0;
|
path[pos] = 0;
|
||||||
|
|
||||||
auto up = []( vec2& p ) { p.y -= 1; };
|
auto up = []( vec2& p ) { p.y -= 1; };
|
||||||
auto down = []( vec2& p ) { p.y += 1; };
|
auto down = []( vec2& p ) { p.y += 1; };
|
||||||
auto left = []( vec2& p ) { p.x -= 1; };
|
auto left = []( vec2& p ) { p.x -= 1; };
|
||||||
auto right = []( vec2& p ) { p.x += 1; };
|
auto right = []( vec2& p ) { p.x += 1; };
|
||||||
|
|
||||||
void (*stepSingle)(vec2&);
|
void (*stepSingle)(vec2&);
|
||||||
|
|
||||||
int stepCounter = 0;
|
int stepCounter = 0;
|
||||||
|
|
||||||
for ( auto& element : wire )
|
for ( auto& element : wire )
|
||||||
{
|
{
|
||||||
char dir = element[0];
|
char dir = element[0];
|
||||||
int steps = std::stoi( element.substr( 1, element.size() ) );
|
int steps = std::stoi( element.substr( 1, element.size() ) );
|
||||||
|
|
||||||
switch ( dir )
|
switch ( dir )
|
||||||
{
|
{
|
||||||
case 'U': stepSingle = up; break;
|
case 'U': stepSingle = up; break;
|
||||||
case 'D': stepSingle = down; break;
|
case 'D': stepSingle = down; break;
|
||||||
case 'R': stepSingle = right; break;
|
case 'R': stepSingle = right; break;
|
||||||
case 'L': stepSingle = left; break;
|
case 'L': stepSingle = left; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < steps; i++ )
|
for( int i = 0; i < steps; i++ )
|
||||||
{
|
{
|
||||||
stepSingle( pos );
|
stepSingle( pos );
|
||||||
path[pos] = ++stepCounter;
|
path[pos] = ++stepCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
std::vector<std::string> wireS1 = tokenise( input );
|
std::vector<std::string> wireS1 = tokenise( input );
|
||||||
|
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
std::vector<std::string> wireS2 = tokenise( input );
|
std::vector<std::string> wireS2 = tokenise( input );
|
||||||
|
|
||||||
auto path1 = genPath(wireS1);
|
auto path1 = genPath(wireS1);
|
||||||
auto path2 = genPath(wireS2);
|
auto path2 = genPath(wireS2);
|
||||||
|
|
||||||
int res = INFINITY;
|
int res = INFINITY;
|
||||||
|
|
||||||
for ( auto [pos, steps] : path2 )
|
for ( auto [pos, steps] : path2 )
|
||||||
{
|
{
|
||||||
// Intersect
|
// Intersect
|
||||||
if ( path1.count( pos ) > 0 )
|
if ( path1.count( pos ) > 0 )
|
||||||
{
|
{
|
||||||
std::cout << pos.x << ":" << pos.y << " " << steps << std::endl;
|
std::cout << pos.x << ":" << pos.y << " " << steps << std::endl;
|
||||||
if ( steps == 0 ) continue;
|
if ( steps == 0 ) continue;
|
||||||
res = std::min( res, path1[pos] + path2[pos] );
|
res = std::min( res, path1[pos] + path2[pos] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Shortest Distance to Complete : " << res << std::endl;
|
std::cout << "Shortest Distance to Complete : " << res << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
R992,U284,L447,D597,R888,D327,R949,U520,R27,U555,L144,D284,R538,U249,R323,U297,R136,U838,L704,D621,R488,U856,R301,U539,L701,U363,R611,D94,L734,D560,L414,U890,R236,D699,L384,D452,R702,D637,L164,U410,R649,U901,L910,D595,R339,D346,R959,U777,R218,D667,R534,D762,R484,D914,L25,U959,R984,D922,R612,U999,L169,D599,L604,D357,L217,D327,L730,D949,L565,D332,L114,D512,R460,D495,L187,D697,R313,U319,L8,D915,L518,D513,R738,U9,R137,U542,L188,U440,R576,D307,R734,U58,R285,D401,R166,U156,L859,U132,L10,U753,L933,U915,R459,D50,R231,D166,L253,U844,R585,D871,L799,U53,R785,U336,R622,D108,R555,D918,L217,D668,L220,U738,L997,D998,R964,D456,L54,U930,R985,D244,L613,D116,L994,D20,R949,D245,L704,D564,L210,D13,R998,U951,L482,U579,L793,U680,L285,U770,L975,D54,R79,U613,L907,U467,L256,D783,R883,U810,R409,D508,L898,D286,L40,U741,L759,D549,R210,U411,R638,D643,L784,U538,L739,U771,L773,U491,L303,D425,L891,U182,R412,U951,L381,U501,R482,D625,R870,D320,L464,U555,R566,D781,L540,D754,L211,U73,L321,D869,R994,D177,R496,U383,R911,U819,L651,D774,L591,U666,L883,U767,R232,U822,L499,U44,L45,U873,L98,D487,L47,U803,R855,U256,R567,D88,R138,D678,L37,U38,R783,U569,L646,D261,L597,U275,L527,U48,R433,D324,L631,D160,L145,D128,R894,U223,R664,U510,R756,D700,R297,D361,R837,U996,L769,U813,L477,U420,L172,U482,R891,D379,L329,U55,R284,U155,L816,U659,L671,U996,R997,U252,R514,D718,L661,D625,R910,D960,L39,U610,R853,U859,R174,U215,L603,U745,L587,D736,R365,U78,R306,U158,L813,U885,R558,U631,L110,D232,L519,D366,R909,D10,R294
|
R992,U284,L447,D597,R888,D327,R949,U520,R27,U555,L144,D284,R538,U249,R323,U297,R136,U838,L704,D621,R488,U856,R301,U539,L701,U363,R611,D94,L734,D560,L414,U890,R236,D699,L384,D452,R702,D637,L164,U410,R649,U901,L910,D595,R339,D346,R959,U777,R218,D667,R534,D762,R484,D914,L25,U959,R984,D922,R612,U999,L169,D599,L604,D357,L217,D327,L730,D949,L565,D332,L114,D512,R460,D495,L187,D697,R313,U319,L8,D915,L518,D513,R738,U9,R137,U542,L188,U440,R576,D307,R734,U58,R285,D401,R166,U156,L859,U132,L10,U753,L933,U915,R459,D50,R231,D166,L253,U844,R585,D871,L799,U53,R785,U336,R622,D108,R555,D918,L217,D668,L220,U738,L997,D998,R964,D456,L54,U930,R985,D244,L613,D116,L994,D20,R949,D245,L704,D564,L210,D13,R998,U951,L482,U579,L793,U680,L285,U770,L975,D54,R79,U613,L907,U467,L256,D783,R883,U810,R409,D508,L898,D286,L40,U741,L759,D549,R210,U411,R638,D643,L784,U538,L739,U771,L773,U491,L303,D425,L891,U182,R412,U951,L381,U501,R482,D625,R870,D320,L464,U555,R566,D781,L540,D754,L211,U73,L321,D869,R994,D177,R496,U383,R911,U819,L651,D774,L591,U666,L883,U767,R232,U822,L499,U44,L45,U873,L98,D487,L47,U803,R855,U256,R567,D88,R138,D678,L37,U38,R783,U569,L646,D261,L597,U275,L527,U48,R433,D324,L631,D160,L145,D128,R894,U223,R664,U510,R756,D700,R297,D361,R837,U996,L769,U813,L477,U420,L172,U482,R891,D379,L329,U55,R284,U155,L816,U659,L671,U996,R997,U252,R514,D718,L661,D625,R910,D960,L39,U610,R853,U859,R174,U215,L603,U745,L587,D736,R365,U78,R306,U158,L813,U885,R558,U631,L110,D232,L519,D366,R909,D10,R294
|
||||||
L1001,D833,L855,D123,R36,U295,L319,D700,L164,U576,L68,D757,R192,D738,L640,D660,R940,D778,R888,U772,R771,U900,L188,D464,L572,U184,R889,D991,L961,U751,R560,D490,L887,D748,R37,U910,L424,D401,L385,U415,L929,U193,R710,D855,L596,D323,L966,D505,L422,D139,L108,D135,R737,U176,R538,D173,R21,D951,R949,D61,L343,U704,R127,U468,L240,D834,L858,D127,R328,D863,R329,U477,R131,U864,R997,D38,R418,U611,R28,U705,R148,D414,R786,U264,L785,D650,R201,D250,R528,D910,R670,U309,L658,U190,R704,U21,R288,D7,R930,U62,R782,U621,R328,D725,R305,U700,R494,D137,R969,U142,L867,U577,R300,U162,L13,D698,R333,U865,R941,U796,L60,U902,L784,U832,R78,D578,R196,D390,R728,D922,R858,D994,L457,U547,R238,D345,R329,D498,R873,D212,R501,U474,L657,U910,L335,U133,R213,U417,R698,U829,L2,U704,L273,D83,R231,D247,R675,D23,L692,D472,L325,D659,L408,U746,L715,U395,L596,U296,R52,D849,L713,U815,R684,D551,L319,U768,R176,D182,R557,U731,R314,D543,L9,D256,R38,D809,L567,D332,R375,D572,R81,D479,L71,U968,L831,D247,R989,U390,R463,D576,R740,D539,R488,U367,L596,U375,L763,D824,R70,U448,R979,D977,L744,D379,R488,D671,L516,D334,L542,U517,L488,D390,L713,D932,L28,U924,L448,D229,L488,D501,R19,D910,L979,D411,R711,D824,L973,U291,R794,D485,R208,U370,R655,U450,L40,D804,L374,D671,R962,D829,L209,U111,L84,D876,L832,D747,L733,D560,L702,D972,R188,U817,L111,U26,L492,U485,L71,D59,L269,D870,L152,U539,R65,D918,L932,D260,L485,U77,L699,U254,R924,U643,L264,U96,R395,D917,R360,U354,R101,D682,R854,U450,L376,D378,R872,D311,L881,U630,R77,D766,R672
|
L1001,D833,L855,D123,R36,U295,L319,D700,L164,U576,L68,D757,R192,D738,L640,D660,R940,D778,R888,U772,R771,U900,L188,D464,L572,U184,R889,D991,L961,U751,R560,D490,L887,D748,R37,U910,L424,D401,L385,U415,L929,U193,R710,D855,L596,D323,L966,D505,L422,D139,L108,D135,R737,U176,R538,D173,R21,D951,R949,D61,L343,U704,R127,U468,L240,D834,L858,D127,R328,D863,R329,U477,R131,U864,R997,D38,R418,U611,R28,U705,R148,D414,R786,U264,L785,D650,R201,D250,R528,D910,R670,U309,L658,U190,R704,U21,R288,D7,R930,U62,R782,U621,R328,D725,R305,U700,R494,D137,R969,U142,L867,U577,R300,U162,L13,D698,R333,U865,R941,U796,L60,U902,L784,U832,R78,D578,R196,D390,R728,D922,R858,D994,L457,U547,R238,D345,R329,D498,R873,D212,R501,U474,L657,U910,L335,U133,R213,U417,R698,U829,L2,U704,L273,D83,R231,D247,R675,D23,L692,D472,L325,D659,L408,U746,L715,U395,L596,U296,R52,D849,L713,U815,R684,D551,L319,U768,R176,D182,R557,U731,R314,D543,L9,D256,R38,D809,L567,D332,R375,D572,R81,D479,L71,U968,L831,D247,R989,U390,R463,D576,R740,D539,R488,U367,L596,U375,L763,D824,R70,U448,R979,D977,L744,D379,R488,D671,L516,D334,L542,U517,L488,D390,L713,D932,L28,U924,L448,D229,L488,D501,R19,D910,L979,D411,R711,D824,L973,U291,R794,D485,R208,U370,R655,U450,L40,D804,L374,D671,R962,D829,L209,U111,L84,D876,L832,D747,L733,D560,L702,D972,R188,U817,L111,U26,L492,U485,L71,D59,L269,D870,L152,U539,R65,D918,L932,D260,L485,U77,L699,U254,R924,U643,L264,U96,R395,D917,R360,U354,R101,D682,R854,U450,L376,D378,R872,D311,L881,U630,R77,D766,R672
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
--- Day 4: Secure Container ---
|
--- Day 4: Secure Container ---
|
||||||
You arrive at the Venus fuel depot only to discover it's protected by a password. The Elves had written the password on a sticky note, but someone threw it out.
|
You arrive at the Venus fuel depot only to discover it's protected by a password. The Elves had written the password on a sticky note, but someone threw it out.
|
||||||
|
|
||||||
However, they do remember a few key facts about the password:
|
However, they do remember a few key facts about the password:
|
||||||
|
|
||||||
It is a six-digit number.
|
It is a six-digit number.
|
||||||
The value is within the range given in your puzzle input.
|
The value is within the range given in your puzzle input.
|
||||||
Two adjacent digits are the same (like 22 in 122345).
|
Two adjacent digits are the same (like 22 in 122345).
|
||||||
Going from left to right, the digits never decrease; they only ever increase or stay the same (like 111123 or 135679).
|
Going from left to right, the digits never decrease; they only ever increase or stay the same (like 111123 or 135679).
|
||||||
Other than the range rule, the following are true:
|
Other than the range rule, the following are true:
|
||||||
|
|
||||||
111111 meets these criteria (double 11, never decreases).
|
111111 meets these criteria (double 11, never decreases).
|
||||||
223450 does not meet these criteria (decreasing pair of digits 50).
|
223450 does not meet these criteria (decreasing pair of digits 50).
|
||||||
123789 does not meet these criteria (no double).
|
123789 does not meet these criteria (no double).
|
||||||
How many different passwords within the range given in your puzzle input meet these criteria?
|
How many different passwords within the range given in your puzzle input meet these criteria?
|
||||||
|
|
||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
An Elf just remembered one more important detail: the two adjacent matching digits are not part of a larger group of matching digits.
|
An Elf just remembered one more important detail: the two adjacent matching digits are not part of a larger group of matching digits.
|
||||||
|
|
||||||
Given this additional criterion, but still ignoring the range rule, the following are now true:
|
Given this additional criterion, but still ignoring the range rule, the following are now true:
|
||||||
|
|
||||||
112233 meets these criteria because the digits never decrease and all repeated digits are exactly two digits long.
|
112233 meets these criteria because the digits never decrease and all repeated digits are exactly two digits long.
|
||||||
123444 no longer meets the criteria (the repeated 44 is part of a larger group of 444).
|
123444 no longer meets the criteria (the repeated 44 is part of a larger group of 444).
|
||||||
111122 meets the criteria (even though 1 is repeated more than twice, it still contains a double 22).
|
111122 meets the criteria (even though 1 is repeated more than twice, it still contains a double 22).
|
||||||
How many different passwords within the range given in your puzzle input meet all of the criteria?
|
How many different passwords within the range given in your puzzle input meet all of the criteria?
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
bool checkPassword( std::string pass )
|
bool checkPassword( std::string pass )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Is less than 6
|
// Is less than 6
|
||||||
if ( pass.length() > 6 || pass.length() < 6 ) return false;
|
if ( pass.length() > 6 || pass.length() < 6 ) return false;
|
||||||
|
|
||||||
// Have any repeats
|
// Have any repeats
|
||||||
bool repeats = false;
|
bool repeats = false;
|
||||||
char lastr = pass[0];
|
char lastr = pass[0];
|
||||||
for ( int i = 1; i < pass.length(); i++ )
|
for ( int i = 1; i < pass.length(); i++ )
|
||||||
{
|
{
|
||||||
if ( lastr == pass[i] ) repeats = true;
|
if ( lastr == pass[i] ) repeats = true;
|
||||||
lastr = pass[i];
|
lastr = pass[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !repeats ) return false;
|
if ( !repeats ) return false;
|
||||||
|
|
||||||
// Digets never decrease
|
// Digets never decrease
|
||||||
bool decreases = true;
|
bool decreases = true;
|
||||||
for ( int i = 1; i < pass.length(); i++ )
|
for ( int i = 1; i < pass.length(); i++ )
|
||||||
if ( pass[i - 1] > pass[i] ) decreases = false;
|
if ( pass[i - 1] > pass[i] ) decreases = false;
|
||||||
|
|
||||||
if ( !decreases ) return false;
|
if ( !decreases ) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
int upper = 893698;
|
int upper = 893698;
|
||||||
int lower = 367479;
|
int lower = 367479;
|
||||||
|
|
||||||
int accumilator = 0;
|
int accumilator = 0;
|
||||||
for ( int i = lower; i < upper; i++ )
|
for ( int i = lower; i < upper; i++ )
|
||||||
if ( checkPassword( std::to_string( i ) ) )
|
if ( checkPassword( std::to_string( i ) ) )
|
||||||
accumilator++;
|
accumilator++;
|
||||||
|
|
||||||
std::cout << "There are : " << accumilator << " valid passwords" << std::endl;
|
std::cout << "There are : " << accumilator << " valid passwords" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
bool checkPassword( std::string pass )
|
bool checkPassword( std::string pass )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Is less than 6
|
// Is less than 6
|
||||||
if ( pass.length() > 6 || pass.length() < 6 ) return false;
|
if ( pass.length() > 6 || pass.length() < 6 ) return false;
|
||||||
|
|
||||||
// Digets never decrease
|
// Digets never decrease
|
||||||
bool decreases = true;
|
bool decreases = true;
|
||||||
for ( int i = 1; i < pass.length(); i++ )
|
for ( int i = 1; i < pass.length(); i++ )
|
||||||
if ( pass[i - 1] > pass[i] ) decreases = false;
|
if ( pass[i - 1] > pass[i] ) decreases = false;
|
||||||
|
|
||||||
if ( !decreases ) return false;
|
if ( !decreases ) return false;
|
||||||
|
|
||||||
// No repeats ( conform w part 2 rule )
|
// No repeats ( conform w part 2 rule )
|
||||||
if ( std::any_of( pass.begin(), pass.end(),
|
if ( std::any_of( pass.begin(), pass.end(),
|
||||||
[&]( auto d ) {
|
[&]( auto d ) {
|
||||||
return std::count( pass.begin(), pass.end(), d ) == 2;
|
return std::count( pass.begin(), pass.end(), d ) == 2;
|
||||||
} ) )
|
} ) )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
int upper = 893698;
|
int upper = 893698;
|
||||||
int lower = 367479;
|
int lower = 367479;
|
||||||
|
|
||||||
int accumilator = 0;
|
int accumilator = 0;
|
||||||
for ( int i = lower; i < upper; i++ )
|
for ( int i = lower; i < upper; i++ )
|
||||||
if ( checkPassword( std::to_string( i ) ) )
|
if ( checkPassword( std::to_string( i ) ) )
|
||||||
accumilator++;
|
accumilator++;
|
||||||
|
|
||||||
std::cout << "There are : " << accumilator << " valid passwords" << std::endl;
|
std::cout << "There are : " << accumilator << " valid passwords" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
--- Day 5: Sunny with a Chance of Asteroids ---
|
--- Day 5: Sunny with a Chance of Asteroids ---
|
||||||
You're starting to sweat as the ship makes its way toward Mercury. The Elves suggest that you get the air conditioner working by upgrading your ship computer to support the Thermal Environment Supervision Terminal.
|
You're starting to sweat as the ship makes its way toward Mercury. The Elves suggest that you get the air conditioner working by upgrading your ship computer to support the Thermal Environment Supervision Terminal.
|
||||||
|
|
||||||
The Thermal Environment Supervision Terminal (TEST) starts by running a diagnostic program (your puzzle input). The TEST diagnostic program will run on your existing Intcode computer after a few modifications:
|
The Thermal Environment Supervision Terminal (TEST) starts by running a diagnostic program (your puzzle input). The TEST diagnostic program will run on your existing Intcode computer after a few modifications:
|
||||||
|
|
||||||
First, you'll need to add two new instructions:
|
First, you'll need to add two new instructions:
|
||||||
|
|
||||||
Opcode 3 takes a single integer as input and saves it to the position given by its only parameter. For example, the instruction 3,50 would take an input value and store it at address 50.
|
Opcode 3 takes a single integer as input and saves it to the position given by its only parameter. For example, the instruction 3,50 would take an input value and store it at address 50.
|
||||||
Opcode 4 outputs the value of its only parameter. For example, the instruction 4,50 would output the value at address 50.
|
Opcode 4 outputs the value of its only parameter. For example, the instruction 4,50 would output the value at address 50.
|
||||||
Programs that use these instructions will come with documentation that explains what should be connected to the input and output. The program 3,0,4,0,99 outputs whatever it gets as input, then halts.
|
Programs that use these instructions will come with documentation that explains what should be connected to the input and output. The program 3,0,4,0,99 outputs whatever it gets as input, then halts.
|
||||||
|
|
||||||
Second, you'll need to add support for parameter modes:
|
Second, you'll need to add support for parameter modes:
|
||||||
|
|
||||||
Each parameter of an instruction is handled based on its parameter mode. Right now, your ship computer already understands parameter mode 0, position mode, which causes the parameter to be interpreted as a position - if the parameter is 50, its value is the value stored at address 50 in memory. Until now, all parameters have been in position mode.
|
Each parameter of an instruction is handled based on its parameter mode. Right now, your ship computer already understands parameter mode 0, position mode, which causes the parameter to be interpreted as a position - if the parameter is 50, its value is the value stored at address 50 in memory. Until now, all parameters have been in position mode.
|
||||||
|
|
||||||
Now, your ship computer will also need to handle parameters in mode 1, immediate mode. In immediate mode, a parameter is interpreted as a value - if the parameter is 50, its value is simply 50.
|
Now, your ship computer will also need to handle parameters in mode 1, immediate mode. In immediate mode, a parameter is interpreted as a value - if the parameter is 50, its value is simply 50.
|
||||||
|
|
||||||
Parameter modes are stored in the same value as the instruction's opcode. The opcode is a two-digit number based only on the ones and tens digit of the value, that is, the opcode is the rightmost two digits of the first value in an instruction. Parameter modes are single digits, one per parameter, read right-to-left from the opcode: the first parameter's mode is in the hundreds digit, the second parameter's mode is in the thousands digit, the third parameter's mode is in the ten-thousands digit, and so on. Any missing modes are 0.
|
Parameter modes are stored in the same value as the instruction's opcode. The opcode is a two-digit number based only on the ones and tens digit of the value, that is, the opcode is the rightmost two digits of the first value in an instruction. Parameter modes are single digits, one per parameter, read right-to-left from the opcode: the first parameter's mode is in the hundreds digit, the second parameter's mode is in the thousands digit, the third parameter's mode is in the ten-thousands digit, and so on. Any missing modes are 0.
|
||||||
|
|
||||||
For example, consider the program 1002,4,3,4,33.
|
For example, consider the program 1002,4,3,4,33.
|
||||||
|
|
||||||
The first instruction, 1002,4,3,4, is a multiply instruction - the rightmost two digits of the first value, 02, indicate opcode 2, multiplication. Then, going right to left, the parameter modes are 0 (hundreds digit), 1 (thousands digit), and 0 (ten-thousands digit, not present and therefore zero):
|
The first instruction, 1002,4,3,4, is a multiply instruction - the rightmost two digits of the first value, 02, indicate opcode 2, multiplication. Then, going right to left, the parameter modes are 0 (hundreds digit), 1 (thousands digit), and 0 (ten-thousands digit, not present and therefore zero):
|
||||||
|
|
||||||
ABCDE
|
ABCDE
|
||||||
1002
|
1002
|
||||||
|
|
||||||
DE - two-digit opcode, 02 == opcode 2
|
DE - two-digit opcode, 02 == opcode 2
|
||||||
C - mode of 1st parameter, 0 == position mode
|
C - mode of 1st parameter, 0 == position mode
|
||||||
B - mode of 2nd parameter, 1 == immediate mode
|
B - mode of 2nd parameter, 1 == immediate mode
|
||||||
A - mode of 3rd parameter, 0 == position mode,
|
A - mode of 3rd parameter, 0 == position mode,
|
||||||
omitted due to being a leading zero
|
omitted due to being a leading zero
|
||||||
This instruction multiplies its first two parameters. The first parameter, 4 in position mode, works like it did before - its value is the value stored at address 4 (33). The second parameter, 3 in immediate mode, simply has value 3. The result of this operation, 33 * 3 = 99, is written according to the third parameter, 4 in position mode, which also works like it did before - 99 is written to address 4.
|
This instruction multiplies its first two parameters. The first parameter, 4 in position mode, works like it did before - its value is the value stored at address 4 (33). The second parameter, 3 in immediate mode, simply has value 3. The result of this operation, 33 * 3 = 99, is written according to the third parameter, 4 in position mode, which also works like it did before - 99 is written to address 4.
|
||||||
|
|
||||||
Parameters that an instruction writes to will never be in immediate mode.
|
Parameters that an instruction writes to will never be in immediate mode.
|
||||||
|
|
||||||
Finally, some notes:
|
Finally, some notes:
|
||||||
|
|
||||||
It is important to remember that the instruction pointer should increase by the number of values in the instruction after the instruction finishes. Because of the new instructions, this amount is no longer always 4.
|
It is important to remember that the instruction pointer should increase by the number of values in the instruction after the instruction finishes. Because of the new instructions, this amount is no longer always 4.
|
||||||
Integers can be negative: 1101,100,-1,4,0 is a valid program (find 100 + -1, store the result in position 4).
|
Integers can be negative: 1101,100,-1,4,0 is a valid program (find 100 + -1, store the result in position 4).
|
||||||
The TEST diagnostic program will start by requesting from the user the ID of the system to test by running an input instruction - provide it 1, the ID for the ship's air conditioner unit.
|
The TEST diagnostic program will start by requesting from the user the ID of the system to test by running an input instruction - provide it 1, the ID for the ship's air conditioner unit.
|
||||||
|
|
||||||
It will then perform a series of diagnostic tests confirming that various parts of the Intcode computer, like parameter modes, function correctly. For each test, it will run an output instruction indicating how far the result of the test was from the expected value, where 0 means the test was successful. Non-zero outputs mean that a function is not working correctly; check the instructions that were run before the output instruction to see which one failed.
|
It will then perform a series of diagnostic tests confirming that various parts of the Intcode computer, like parameter modes, function correctly. For each test, it will run an output instruction indicating how far the result of the test was from the expected value, where 0 means the test was successful. Non-zero outputs mean that a function is not working correctly; check the instructions that were run before the output instruction to see which one failed.
|
||||||
|
|
||||||
Finally, the program will output a diagnostic code and immediately halt. This final output isn't an error; an output followed immediately by a halt means the program finished. If all outputs were zero except the diagnostic code, the diagnostic program ran successfully.
|
Finally, the program will output a diagnostic code and immediately halt. This final output isn't an error; an output followed immediately by a halt means the program finished. If all outputs were zero except the diagnostic code, the diagnostic program ran successfully.
|
||||||
|
|
||||||
After providing 1 to the only input instruction and passing all the tests, what diagnostic code does the program produce?
|
After providing 1 to the only input instruction and passing all the tests, what diagnostic code does the program produce?
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +1,53 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<int> tokenise( std::string input )
|
std::vector<int> tokenise( std::string input )
|
||||||
{
|
{
|
||||||
std::stringstream ssInput( input );
|
std::stringstream ssInput( input );
|
||||||
std::vector<int> stream;
|
std::vector<int> stream;
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
while( std::getline( ssInput, s, ',' ) ) {
|
while( std::getline( ssInput, s, ',' ) ) {
|
||||||
stream.push_back( std::stoi( s ) );
|
stream.push_back( std::stoi( s ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntCodeCPU
|
class IntCodeCPU
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
IntCodeCPU();
|
IntCodeCPU();
|
||||||
|
|
||||||
std::vector<int> Program;
|
std::vector<int> Program;
|
||||||
int ProgramCounter;
|
int ProgramCounter;
|
||||||
|
|
||||||
void SetProgram( std::vector<int> program )
|
void SetProgram( std::vector<int> program )
|
||||||
{
|
{
|
||||||
Program = program;
|
Program = program;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterOpcode( int opcode )
|
void RegisterOpcode( int opcode )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
std::getline( infile, input );
|
std::getline( infile, input );
|
||||||
|
|
||||||
std::vector<int> program = tokenise( input );
|
std::vector<int> program = tokenise( input );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
--- Day 6: Universal Orbit Map ---
|
--- Day 6: Universal Orbit Map ---
|
||||||
You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input).
|
You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input).
|
||||||
|
|
||||||
Except for the universal Center of Mass (COM), every object in space is in orbit around exactly one other object. An orbit looks roughly like this:
|
Except for the universal Center of Mass (COM), every object in space is in orbit around exactly one other object. An orbit looks roughly like this:
|
||||||
|
|
||||||
\
|
\
|
||||||
\
|
\
|
||||||
|
|
|
|
||||||
|
|
|
|
||||||
AAA--> o o <--BBB
|
AAA--> o o <--BBB
|
||||||
|
|
|
|
||||||
|
|
|
|
||||||
/
|
/
|
||||||
/
|
/
|
||||||
In this diagram, the object BBB is in orbit around AAA. The path that BBB takes around AAA (drawn with lines) is only partly shown. In the map data, this orbital relationship is written AAA)BBB, which means "BBB is in orbit around AAA".
|
In this diagram, the object BBB is in orbit around AAA. The path that BBB takes around AAA (drawn with lines) is only partly shown. In the map data, this orbital relationship is written AAA)BBB, which means "BBB is in orbit around AAA".
|
||||||
|
|
||||||
Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the download. To verify maps, the Universal Orbit Map facility uses orbit count checksums - the total number of direct orbits (like the one shown above) and indirect orbits.
|
Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the download. To verify maps, the Universal Orbit Map facility uses orbit count checksums - the total number of direct orbits (like the one shown above) and indirect orbits.
|
||||||
|
|
||||||
Whenever A orbits B and B orbits C, then A indirectly orbits C. This chain can be any number of objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D.
|
Whenever A orbits B and B orbits C, then A indirectly orbits C. This chain can be any number of objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D.
|
||||||
|
|
||||||
For example, suppose you have the following map:
|
For example, suppose you have the following map:
|
||||||
|
|
||||||
COM)B
|
COM)B
|
||||||
B)C
|
B)C
|
||||||
C)D
|
C)D
|
||||||
D)E
|
D)E
|
||||||
E)F
|
E)F
|
||||||
B)G
|
B)G
|
||||||
G)H
|
G)H
|
||||||
D)I
|
D)I
|
||||||
E)J
|
E)J
|
||||||
J)K
|
J)K
|
||||||
K)L
|
K)L
|
||||||
Visually, the above map of orbits looks like this:
|
Visually, the above map of orbits looks like this:
|
||||||
|
|
||||||
G - H J - K - L
|
G - H J - K - L
|
||||||
/ /
|
/ /
|
||||||
COM - B - C - D - E - F
|
COM - B - C - D - E - F
|
||||||
\
|
\
|
||||||
I
|
I
|
||||||
In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left.
|
In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left.
|
||||||
|
|
||||||
Here, we can count the total number of orbits as follows:
|
Here, we can count the total number of orbits as follows:
|
||||||
|
|
||||||
D directly orbits C and indirectly orbits B and COM, a total of 3 orbits.
|
D directly orbits C and indirectly orbits B and COM, a total of 3 orbits.
|
||||||
L directly orbits K and indirectly orbits J, E, D, C, B, and COM, a total of 7 orbits.
|
L directly orbits K and indirectly orbits J, E, D, C, B, and COM, a total of 7 orbits.
|
||||||
COM orbits nothing.
|
COM orbits nothing.
|
||||||
The total number of direct and indirect orbits in this example is 42.
|
The total number of direct and indirect orbits in this example is 42.
|
||||||
|
|
||||||
What is the total number of direct and indirect orbits in your map data?
|
What is the total number of direct and indirect orbits in your map data?
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,56 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> mapise( std::vector<std::string> input )
|
std::unordered_map<std::string, std::string> mapise( std::vector<std::string> input )
|
||||||
{
|
{
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> ret;
|
std::unordered_map<std::string, std::string> ret;
|
||||||
|
|
||||||
for ( auto& str : input )
|
for ( auto& str : input )
|
||||||
{
|
{
|
||||||
std::string first = str.substr(0, 3);
|
std::string first = str.substr(0, 3);
|
||||||
std::string second = str.substr(4, str.size());
|
std::string second = str.substr(4, str.size());
|
||||||
|
|
||||||
ret[first] = second;
|
ret[first] = second;
|
||||||
std::cout << first << " " << second << std::endl;
|
std::cout << first << " " << second << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
std::ifstream infile( argv[1] );
|
std::ifstream infile( argv[1] );
|
||||||
|
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (!infile.eof())
|
while (!infile.eof())
|
||||||
{
|
{
|
||||||
|
|
||||||
std::getline(infile, line);
|
std::getline(infile, line);
|
||||||
if ( line.length() == 0 ) continue;
|
if ( line.length() == 0 ) continue;
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int accumilator = 0;
|
int accumilator = 0;
|
||||||
|
|
||||||
auto map = mapise( lines );
|
auto map = mapise( lines );
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string>::iterator it;
|
std::unordered_map<std::string, std::string>::iterator it;
|
||||||
for (it = map.begin(); it != map.end(); it++)
|
for (it = map.begin(); it != map.end(); it++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Sum of direct and indirect orbits : " << accumilator << std::endl;
|
std::cout << "Sum of direct and indirect orbits : " << accumilator << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
30
2020/3.js
Normal file
30
2020/3.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const input = fs.readFileSync('3.txt').toString().split('\n');
|
||||||
|
|
||||||
|
function countTrees(lines, xoff, yoff)
|
||||||
|
{
|
||||||
|
let treeCount = 0;
|
||||||
|
let length = lines[0].length - 1;
|
||||||
|
let x = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i += yoff)
|
||||||
|
{
|
||||||
|
if (lines[i][x % length] == '#') treeCount++;
|
||||||
|
x += xoff;
|
||||||
|
}
|
||||||
|
|
||||||
|
return treeCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = countTrees(input, 3, 1);
|
||||||
|
console.log(`Part 1, tree count: ${count}`);
|
||||||
|
|
||||||
|
let total1 = countTrees(input, 1, 1);
|
||||||
|
let total2 = countTrees(input, 3, 1);
|
||||||
|
let total3 = countTrees(input, 5, 1);
|
||||||
|
let total4 = countTrees(input, 7, 1);
|
||||||
|
let total5 = countTrees(input, 1, 2);
|
||||||
|
|
||||||
|
console.log(`Part 2, tree count: ${total1 * total2 * total3 * total4 * total5}`);
|
||||||
|
|
||||||
|
|
||||||
323
2020/3.txt
Normal file
323
2020/3.txt
Normal file
@@ -0,0 +1,323 @@
|
|||||||
|
.....##.#.....#........#....##.
|
||||||
|
....#...#...#.#.......#........
|
||||||
|
.....##.#......#.......#.......
|
||||||
|
...##.........#...#............
|
||||||
|
........#...#.......#.........#
|
||||||
|
..........#......#..#....#....#
|
||||||
|
..................#..#..#....##
|
||||||
|
.....##...#..#..#..#..#.##.....
|
||||||
|
..##.###....#.#.........#......
|
||||||
|
#.......#......#......#....##..
|
||||||
|
.....#..#.#.......#......#.....
|
||||||
|
............#............#.....
|
||||||
|
...#.#........#........#.#.##.#
|
||||||
|
.#..#...#.....#....##..........
|
||||||
|
##..........#...#...#..........
|
||||||
|
...........#...###...#.......##
|
||||||
|
.#..#............#........#....
|
||||||
|
##.#..#.....#.......#.#.#......
|
||||||
|
.##.....#....#.#.......#.##....
|
||||||
|
..##...........#.......#..##.#.
|
||||||
|
##...#.#........#..#...#...#..#
|
||||||
|
.#..#........#.#.......#..#...#
|
||||||
|
.##.##.##...#.#............##..
|
||||||
|
..#.#..###......#..#......#....
|
||||||
|
.#..#..#.##.#.##.#.#...........
|
||||||
|
...#....#..#.#.#.........#..#..
|
||||||
|
......#.#....##.##......#......
|
||||||
|
#....#.##.##....#..#...........
|
||||||
|
...#.#.#.#..#.#..#.#..#.##.....
|
||||||
|
#.....#######.###.##.#.#.#.....
|
||||||
|
..#.##.....##......#...#.......
|
||||||
|
..#....#..#...##.#..#..#..#..#.
|
||||||
|
.............#.##....#.........
|
||||||
|
.#....#.##.....#...............
|
||||||
|
.#............#....#...#.##....
|
||||||
|
.#.....#.##.###.......#..#.....
|
||||||
|
.#...#.........#.......#..#....
|
||||||
|
..#.#..#.##.......##...........
|
||||||
|
.....##..#..#..#..#.##..#.....#
|
||||||
|
..##............##...#..#......
|
||||||
|
...#..#....#..##.....##..#.#...
|
||||||
|
#.....##....#.#.#...#...#..##.#
|
||||||
|
#.#..#.........#.##.#...#.#.#..
|
||||||
|
.....#.#....##....#............
|
||||||
|
#.......#..#.....##..#...#...#.
|
||||||
|
.....#.#...#...#..#......#.....
|
||||||
|
..##....#.#.#.#.#..#...........
|
||||||
|
##..#...#.........#......#...#.
|
||||||
|
..#...#.#.#.#..#.#.##..##......
|
||||||
|
#............###.....###.......
|
||||||
|
..........#...#........###.....
|
||||||
|
.......##...#...#...#........#.
|
||||||
|
.#..#.##.#.....................
|
||||||
|
.#..##........##.##...#.......#
|
||||||
|
.......##......#.....#......#..
|
||||||
|
.##.#.....#......#......#......
|
||||||
|
#...##.#.#...#.#...............
|
||||||
|
........#..#...#.##.......#....
|
||||||
|
...................#...#...##..
|
||||||
|
...#...#.........#.....#..#.#..
|
||||||
|
.###..#........#..##.##..#.##..
|
||||||
|
#...#.....#.....#.....#..#..#..
|
||||||
|
###..#.....#.#.#.#......#....#.
|
||||||
|
#........#....##.#...##........
|
||||||
|
.#.#..##........##....##.#.#...
|
||||||
|
#...#....#.###.#.#.........#...
|
||||||
|
...#...##..###.......#.........
|
||||||
|
......#....#..##..#.....#.#....
|
||||||
|
........#...##...###......##...
|
||||||
|
..........##.#.......##........
|
||||||
|
...#....#......#...##.....#....
|
||||||
|
###.#.....#.#..#..#....#...#..#
|
||||||
|
.#.....#.#....#...............#
|
||||||
|
..#....#....####....###....#.#.
|
||||||
|
....##........#..#.##.#....#...
|
||||||
|
.......##...#...#..#....####...
|
||||||
|
#...##.#......##...#..#........
|
||||||
|
..##..#.##....#.......##.#.#...
|
||||||
|
..#.#...............#...#.#....
|
||||||
|
....#.....#.#.....#.##.......#.
|
||||||
|
...#.#..##.#.#..............##.
|
||||||
|
..#.....#...#.............#.##.
|
||||||
|
##..#.#...#........#..#.....##.
|
||||||
|
...........##...#.#.###...#....
|
||||||
|
...#.#.#..#..................#.
|
||||||
|
.#...##.............#...#......
|
||||||
|
..#..#...#.#.......#...#.....#.
|
||||||
|
..##.......#.#.................
|
||||||
|
.##..#........###.....#....#.##
|
||||||
|
......#..###.......#....##....#
|
||||||
|
....#.....#.................#..
|
||||||
|
........#...#...#..............
|
||||||
|
...#..#.###.......#..#.#.#.##..
|
||||||
|
..#...#.....#....#.........#...
|
||||||
|
...#.............#........###..
|
||||||
|
......#..............#......#..
|
||||||
|
#..#...........#...#..........#
|
||||||
|
...##...#.###..#...#.....#.#...
|
||||||
|
....#..##......#.......##......
|
||||||
|
....#....##.#...#.#..#....#...#
|
||||||
|
.#...........#..#....##...#..##
|
||||||
|
..#.#.................###.#...#
|
||||||
|
..#.#.#...##...........#.......
|
||||||
|
..........#..##...#.#..##....##
|
||||||
|
........#........#.##..#.#...#.
|
||||||
|
.....#...##.......##......#...#
|
||||||
|
....#...#..#..#.....#..........
|
||||||
|
.#..#......#..#..#..###.......#
|
||||||
|
.##..........#...#...#.#.....##
|
||||||
|
..#..........#.#.#...###.......
|
||||||
|
....#................#...##....
|
||||||
|
.##..#....#..........#.#.#.....
|
||||||
|
..##...#.#........#.....#.##...
|
||||||
|
....####.....#..#.........##..#
|
||||||
|
......#.........#...#..........
|
||||||
|
....#...................#..##..
|
||||||
|
.##....#.#.........#....#...#..
|
||||||
|
....##...##.....#..####........
|
||||||
|
..##.#....#.#.......##...#.....
|
||||||
|
#...#.#.#...#..#..##.....#.....
|
||||||
|
#..................###.....#...
|
||||||
|
#.#.....#.......#.#...###.#....
|
||||||
|
.#..#....#............#........
|
||||||
|
#.#....#..#.#...............#..
|
||||||
|
..#..#..#.............#......#.
|
||||||
|
..#.......##...................
|
||||||
|
.#....#.........#....#.#.#..#..
|
||||||
|
....#....#..#...............#..
|
||||||
|
......#..#..##......#.........#
|
||||||
|
..#.##........##......#..#..#.#
|
||||||
|
#.....#.#....#.........##...#..
|
||||||
|
###..............#....###...##.
|
||||||
|
....#..##......#.......##......
|
||||||
|
......#...#.##......##....#..#.
|
||||||
|
..........#....#..##.......#..#
|
||||||
|
.#..#...##..#...........#..#..#
|
||||||
|
.....#....#...#..###...###....#
|
||||||
|
.#####..#...#.#.#..#.#.###...##
|
||||||
|
..##............##.#...#.##...#
|
||||||
|
.##..#...#...#....##.#..#..##..
|
||||||
|
.#....#...#............##..#...
|
||||||
|
.#.#......#....#....#..##..##..
|
||||||
|
.........#...#.......#.##..#...
|
||||||
|
#.........#.....##.....#..#..#.
|
||||||
|
...##.#...#...#..#..#....##..##
|
||||||
|
.#............#...#....##......
|
||||||
|
..#...#.##.........#.#......#.#
|
||||||
|
....#.##........#.........#..##
|
||||||
|
#.........#......#.#......#..#.
|
||||||
|
........#.#.......#.#........#.
|
||||||
|
..#..........##.#...#..#.#.....
|
||||||
|
..#...#....#...#...#..#.#..#.#.
|
||||||
|
.#.........#....#..#####..#....
|
||||||
|
#.#....#.#.###...#.............
|
||||||
|
..##...........##......##......
|
||||||
|
#.....#..#....#...............#
|
||||||
|
...#.#..#....##......#...##....
|
||||||
|
...#........#.....#...#..#.....
|
||||||
|
.#......##.........#......#....
|
||||||
|
..#..###.##...#.#.....#........
|
||||||
|
.............#......#..#.......
|
||||||
|
..#...............#.#...#..#..#
|
||||||
|
.......#..#...#.#####......#..#
|
||||||
|
.........#.....#...............
|
||||||
|
##........#............#.#.....
|
||||||
|
.#...#.....#..#..#...#....#...#
|
||||||
|
..#....#....##......##.....#.#.
|
||||||
|
#...##..##......#...#....#.....
|
||||||
|
....#.#.#.....###....##.##....#
|
||||||
|
..........##...##.......#......
|
||||||
|
..#.......#...##.#....##.##....
|
||||||
|
....#........................#.
|
||||||
|
...#...#.#.##...#.....#...#..#.
|
||||||
|
.#....##..#..#..........##..##.
|
||||||
|
.#.....#..#...#.##.....#.......
|
||||||
|
.#.##...#.#..#.....##....#...#.
|
||||||
|
.##...#........##....#..#......
|
||||||
|
.....#........#..........#.#..#
|
||||||
|
....#..##.......#..#.....#.....
|
||||||
|
...........#...#........#.##..#
|
||||||
|
.....#..#....#..#.#.....#....##
|
||||||
|
.....#....#.##.#..##...........
|
||||||
|
...##.......##.........#.......
|
||||||
|
...............##..#....#.#....
|
||||||
|
.......###..#........#..####.##
|
||||||
|
.......#.##...#.#....#.####....
|
||||||
|
....#...............#..........
|
||||||
|
##.#.......#.....#......#...#..
|
||||||
|
......##.....#....#.....#..#..#
|
||||||
|
.....#...##.............#......
|
||||||
|
#.#.##.#.....#..#........#.....
|
||||||
|
......##....#..#........#......
|
||||||
|
............#........#..#.#....
|
||||||
|
##.......#......#...####..#.##.
|
||||||
|
..##..#...#.............#.##...
|
||||||
|
.....#..##......#.##......###..
|
||||||
|
............#........#........#
|
||||||
|
#.#.#.#...#.#.....#.........#..
|
||||||
|
.........#...............#.....
|
||||||
|
.............###.#.......#....#
|
||||||
|
###.##..#..#..........#....#...
|
||||||
|
#......#...#..#..#.....#.##....
|
||||||
|
............#....#....#..#.....
|
||||||
|
..#.#....#...#......#.#..#..##.
|
||||||
|
...#........................#..
|
||||||
|
#.#...#..........#......#.#....
|
||||||
|
.........#................#...#
|
||||||
|
##.....#....#........##.......#
|
||||||
|
#...##........#...#...........#
|
||||||
|
...#...#..........##.......#.#.
|
||||||
|
..#.#.#....#......##...........
|
||||||
|
...#.#...#.##.#..#.#.##........
|
||||||
|
#....##.....###..#.......#.....
|
||||||
|
###.....#.#.#...#..#.........##
|
||||||
|
..#......#..###...#.#.#.....#.#
|
||||||
|
.#....#.....#............#..##.
|
||||||
|
....#....##..........#.....##..
|
||||||
|
#...........#....#...#..#...##.
|
||||||
|
..#.......#.....#..........#...
|
||||||
|
.#..#................#......#..
|
||||||
|
..#......#.#...#..#.#....#....#
|
||||||
|
...#..#...###..#..##....#.#....
|
||||||
|
..#..............#.....#.......
|
||||||
|
...#.#...#.........#.#.........
|
||||||
|
##......##...........##.#.##..#
|
||||||
|
..#..##..#....#.#......#.#...##
|
||||||
|
...#.###....###...#.....#......
|
||||||
|
#.#................#......#....
|
||||||
|
..#.....#.....#....##.......#..
|
||||||
|
.#.#...............##..#.......
|
||||||
|
...#....#.......#.#.....##..#..
|
||||||
|
.........#....#.......#.#...##.
|
||||||
|
#....#......##.#.........##...#
|
||||||
|
#.............#..##.#.#..##....
|
||||||
|
...#....#..#...#....#.#.#.#...#
|
||||||
|
.#....#....#..##.....#.#...###.
|
||||||
|
##............#.#...##.#..#.#..
|
||||||
|
##.#....##.....#..#..###....#..
|
||||||
|
##....#................##......
|
||||||
|
...##..#...#..###....#.....##..
|
||||||
|
.#...##......#..#.#.....#...#..
|
||||||
|
..##......##...#.##.......#....
|
||||||
|
......#.....#.....##........#.#
|
||||||
|
##....#...........#............
|
||||||
|
#.......#....#..#.##..##.#..#..
|
||||||
|
.#....##.#.....#..#..#.........
|
||||||
|
.#....#.#.#...#.....##.....#.#.
|
||||||
|
.......##.#.#........#......##.
|
||||||
|
##........#.##.......#...#..#..
|
||||||
|
...###..##....#.#....#.#.......
|
||||||
|
......#.......#...##.....#...#.
|
||||||
|
..#......##.#......#.....#.....
|
||||||
|
.....#.....###...#.............
|
||||||
|
#...#.#...#...#..#......#......
|
||||||
|
#.....#.......###.#....###.#...
|
||||||
|
...#.......#....####....##..#..
|
||||||
|
#.#.....#....#........#.......#
|
||||||
|
.........#.......#......#.#...#
|
||||||
|
..##....#.....##...............
|
||||||
|
..........#..#.#..#......#.....
|
||||||
|
..................##...##.#....
|
||||||
|
........#.......#...#..#.#.#...
|
||||||
|
.....#.#..##..#..#.#..#.......#
|
||||||
|
.....#........#..#..#....#....#
|
||||||
|
##............#..#..#...#....#.
|
||||||
|
.....#....................##..#
|
||||||
|
........##.#....###............
|
||||||
|
##.......#.##................#.
|
||||||
|
.....###.#..#..#...#....###.##.
|
||||||
|
.#......#.#....#.....##.#......
|
||||||
|
...##......##.........#...#....
|
||||||
|
....####..............#........
|
||||||
|
#...#.#..##..##.........##.....
|
||||||
|
......#......#....#..#.........
|
||||||
|
#.....#.....#.##...............
|
||||||
|
..#.##..#...##.#.####..#....###
|
||||||
|
#..#......#....#.##..##...#.#..
|
||||||
|
#....#.......#.....#.....#.#...
|
||||||
|
##.......#.....##...#.....#....
|
||||||
|
...#...##..........#..##..##..#
|
||||||
|
.###..#..##...#....#...#..#....
|
||||||
|
......##..###.......###...#....
|
||||||
|
....#...#.#.......#.##...##..##
|
||||||
|
#.#......#..##.#.#..#..#..#....
|
||||||
|
......#........#.......#.......
|
||||||
|
..........#.#.....##...........
|
||||||
|
......#..#........#..#.#..###..
|
||||||
|
##..#.............##..#........
|
||||||
|
.........#....#.....#.........#
|
||||||
|
.....#..##...#..#..##.##......#
|
||||||
|
###..#...........#.......#....#
|
||||||
|
...............#....#.#........
|
||||||
|
.##.#...#.#........##....#.....
|
||||||
|
.##.###...##..###....#...#...#.
|
||||||
|
.##..#....#.#.#...#.#.#.#...#..
|
||||||
|
.###.#...#.......#....#..#.....
|
||||||
|
..#..#.#.#.#........#.....##...
|
||||||
|
.#.......#.#...#.#...........##
|
||||||
|
...#.....##....#.....##...#....
|
||||||
|
................#.....####...#.
|
||||||
|
.#.#......#.......##...#.##....
|
||||||
|
.###.........#.#......#..#.#...
|
||||||
|
#......#...#....#..##.......#..
|
||||||
|
.##..#....#..#...........#...#.
|
||||||
|
.#...#.......##........#.##....
|
||||||
|
..#...........#...##...........
|
||||||
|
.....##....##......#....#..#...
|
||||||
|
#......#.#...#.##.#...##....#..
|
||||||
|
#....................#...##...#
|
||||||
|
..#............#........#......
|
||||||
|
.............#.........##.....#
|
||||||
|
...#...#......##.#...#...#.#...
|
||||||
|
..#...#.#.................#....
|
||||||
|
....##...#....#...###.##......#
|
||||||
|
...#....#...#..#...#....#.....#
|
||||||
|
...##.#........#..#.........#..
|
||||||
|
..##.....#..##...#.....##...#..
|
||||||
|
#.........#.#.#...#......#...#.
|
||||||
|
#.#...........#...#..#..#..##..
|
||||||
|
..#..#..##....#..........#.###.
|
||||||
|
.....#..#....#.#...#...#..#..#.
|
||||||
|
###.....#..#.................#.
|
||||||
|
.#..##.##.#......#....##..#....
|
||||||
15
2020/4.js
Normal file
15
2020/4.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const input = fs.readFileSync('4.txt').toString().split('\n');
|
||||||
|
|
||||||
|
const requiredFields = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid'];
|
||||||
|
|
||||||
|
let currentPassport = {};
|
||||||
|
for (const line of input)
|
||||||
|
{
|
||||||
|
console.log(input + '\nbruh')
|
||||||
|
if (line == '')
|
||||||
|
{
|
||||||
|
console.log('new passport')
|
||||||
|
currentPassport = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
1133
2020/4.txt
Normal file
1133
2020/4.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user