Merge branch 'master' of https://github.com/plane000/Examples
This commit is contained in:
Binary file not shown.
BIN
AdventOfCode2018/2ndDay/challenge1/a.out
Executable file
BIN
AdventOfCode2018/2ndDay/challenge1/a.out
Executable file
Binary file not shown.
@@ -1,7 +1,250 @@
|
||||
abcdef
|
||||
bababc
|
||||
abbcde
|
||||
abcccd
|
||||
aabcdd
|
||||
abcdee
|
||||
ababab
|
||||
ybruvapdgixszyckwtfqjonsie
|
||||
mbruvapxghslyyckwtfqjonsie
|
||||
mbruvapdghslzyckwtkujonsie
|
||||
rwruvapdghxlzyckwtfqjcnsie
|
||||
obruvapdgtxlzyckwtfqionsie
|
||||
lbruvapdghxqzyckwtfqjfnsie
|
||||
mbrunapdghxlzyccatfqjonsie
|
||||
mbruvapdghxlzyokltfqjdnsie
|
||||
ybruvapdghxlzmckwtfqjmnsie
|
||||
mbruwaadghxdzyckwtfqjonsie
|
||||
muruvapdghxlzyckvtfqjonsim
|
||||
mbruvapdghxlkyckwtxqjonjie
|
||||
mbruvaqdghxlzyckwtfqjrnnie
|
||||
mwruvapdghdlzyckttfqjonsie
|
||||
mbruvapdgtelzyckwxfqjonsie
|
||||
mbruvapdohxlzvckwtfqjonhie
|
||||
mbrugapdgbxlzyckwtfqjynsie
|
||||
mbruvapdghxlzyckwtlqjonjiu
|
||||
mbruvapwghxlzyckwafqjonbie
|
||||
wbruvapdghxlhyckwtfqjonsii
|
||||
mbruvapdghxlzyckwtcqnonsiq
|
||||
mbyuvapighxlzybkwtfqjonsie
|
||||
mbrrvapdghxvzyckwtfqjonsio
|
||||
mhruvapdghrlzyckwtfzjonsie
|
||||
mtruvapvghxlzyckwtfnjonsie
|
||||
mmrlhapdghxlzyckwtfqjonsie
|
||||
mbruvapdgpxlzyjkwtfqjovsie
|
||||
mbrucapdghxlzymkwtzqjonsie
|
||||
mbeuvafdghxlzyckwtfqjonwie
|
||||
mbruvapcghxlayckwtfqjonsii
|
||||
mbruvabdghxlzyckwtfqyansie
|
||||
mbruvjpdghxlzyckwtfqgfnsie
|
||||
lbruvapdghxlzyckwtfqjonriv
|
||||
mbrupapdghxlzycjwtfqronsie
|
||||
mbpuvapdthxlzymkwtfqjonsie
|
||||
mbiuvapdgixlzyckwxfqjonsie
|
||||
mbruvapdghxyzyckwtfcjonsbe
|
||||
mbrurapkghxlzyckwtfqjonzie
|
||||
mbrufapdrhxlzyciwtfqjonsie
|
||||
mbruvapdghxlzbckwtfqjoisae
|
||||
ubruhapdghxlzuckwtfqjonsie
|
||||
mbruvapdjhulzyckwtfqjonshe
|
||||
mbruwapdgyxlzyckntfqjonsie
|
||||
mwruvapdghplzyckwtfqjonsme
|
||||
mbruvapjghtlzyckwtfqgonsie
|
||||
pbruvapdghhlzyckwtfrjonsie
|
||||
mbruvgpdihxqzyckwtfqjonsie
|
||||
mbruvahdohxlzyckwtfijonsie
|
||||
ibuuvapdghxlzyckwtfqjofsie
|
||||
mbruvandghxlzyckwtfqjrnxie
|
||||
mbrjvlpdghxlzyckwgfqjonsie
|
||||
mbruvapogfxlzyckotfqjonsie
|
||||
mbruvrpdghxlzyckutfejonsie
|
||||
mbruvbpdghxlzyhkwtfqjonsip
|
||||
mbruvapdghxlzyckmnfqjensie
|
||||
mbruvapdghvlzyckwtfqjowsix
|
||||
mbruvakdgholzwckwtfqjonsie
|
||||
mbruvapdghxlzackwtfqconsae
|
||||
mbruvapdghxlzyqvwtfqjlnsie
|
||||
mprrvapdgfxlzyckwtfqjonsie
|
||||
mbrunacdghxlhyckwtfqjonsie
|
||||
obruvapdgsxlzyckwtfqjonvie
|
||||
murcvapdghslzyckwtfqjonsie
|
||||
mbruvapdghxlzyzkwmftjonsie
|
||||
mbrwvapdgtvlzyckwtfqjonsie
|
||||
mbxuvapdghxlzqcnwtfqjonsie
|
||||
mbruvaddghxboyckwtfqjonsie
|
||||
mhruvwndghxlzyckwtfqjonsie
|
||||
mbrdvapdghxlzyckwmpqjonsie
|
||||
mbruvapdgyxlzyckizfqjonsie
|
||||
mbruvapdghxlzlckwtfqeowsie
|
||||
mbruvbpdgrxlzyckwtfqjonsxe
|
||||
mbruqapoghxlzyckwtvqjonsie
|
||||
mbouhapdghmlzyckwtfqjonsie
|
||||
mbruvapjghxidyckwtfqjonsie
|
||||
mbsuvapkghxlkyckwtfqjonsie
|
||||
mbruvlpdghxlzycrwtfqjonsis
|
||||
mcrueapdghxlzyckwtfqjynsie
|
||||
muruvapngbxlzyckwtfqjonsie
|
||||
mbruvapdghxlzycawtfyjojsie
|
||||
mbruvbpdghxczyjkwtfqjonsie
|
||||
ybduvapdghxnzyckwtfqjonsie
|
||||
mbruvbpdghxlzyckwtfbjousie
|
||||
mbouvapdghxlzycbwtfqponsie
|
||||
mbruvaedghplzycgwtfqjonsie
|
||||
mbrhvapdghxlzyckytfqjgnsie
|
||||
mbruvapdqbxleyckwtfqjonsie
|
||||
mbruvapddhhldyckwtfqjonsie
|
||||
mbruvapdghxlwrckwtfqjondie
|
||||
mbruvapdmhxlzyckwtfqkonsve
|
||||
xbbuvapdghxlzyckwtfkjonsie
|
||||
mbruvapdghxlzyckwcfqjunkie
|
||||
mbruvapdghxlzyckwtfqxonfib
|
||||
mbrtvapkghxlzyckwtfqeonsie
|
||||
mbruvazdghxldymkwtfqjonsie
|
||||
kbruvapddhxlzfckwtfqjonsie
|
||||
mbouvapdghxlpyckwtfqjoosie
|
||||
mbauvapdghxlzyckwtfqjszsie
|
||||
mbruvapdghtlzyckntfqtonsie
|
||||
mbruvipdggxlzbckwtfqjonsie
|
||||
mbruqapdghrlzyckwtfqjznsie
|
||||
myruvacdghxlzyckwifqjonsie
|
||||
mbruvapdghxlzuckwtfkjocsie
|
||||
mwjuvapdghxlzyckwtfqjonsxe
|
||||
mbruvapxghxlzickwtfqjobsie
|
||||
mbrupapdghxtlyckwtfqjonsie
|
||||
meruvapdjjxlzyckwtfqjonsie
|
||||
mbruvkodghxlzyckwofqjonsie
|
||||
mbruvapdgexlzyckwtgkjonsie
|
||||
mbruvapwghxlzyckwtcqjonsiw
|
||||
mbruvapdghxlzykkwtfqtoxsie
|
||||
mbruvapdahxlzycgwtfwjonsie
|
||||
mbruvapdgwxlhyckhtfqjonsie
|
||||
mbruvapbghxlzycbhmfqjonsie
|
||||
mbruvapdghxvzyzkwtfqjonsin
|
||||
mbrcvapdqhxlzyckwyfqjonsie
|
||||
zbruvaxdghxlzyckwgfqjonsie
|
||||
mtruvapdghxlilckwtfqjonsie
|
||||
bbruvapdghxlzyckwtfmjonsxe
|
||||
mbruvajdghxlzyckwtfqfwnsie
|
||||
mbruvapdgkxlzyckwtfqionpie
|
||||
rbruvapdghxlryckwdfqjonsie
|
||||
mbruvandghxlzyckwmfvjonsie
|
||||
mbruvahdghxlzeckwtfqjonsme
|
||||
mbruvnpcghxlzyckwtfqjobsie
|
||||
mbruvapdghqlzyckwtfbjonsiy
|
||||
mbruvavdghxlzyckwufqjodsie
|
||||
mbruvapdghxlzyckwtfzmovsie
|
||||
mbruvlpdghxuzyckwtfqjoesie
|
||||
mbruvopdghxlzycwwtfqjansie
|
||||
obruvapdghglzybkwtfqjonsie
|
||||
mbpuvlpdghxlcyckwtfqjonsie
|
||||
mbruvaidghxlzyckwtfmjonoie
|
||||
mbruvapdihxzzyckwtfqjonsiy
|
||||
mbquvapdghxlzyckwtfqconsme
|
||||
mbruvapdghslzyckqtfqjojsie
|
||||
mbrzdapdghxmzyckwtfqjonsie
|
||||
mwruvapdghxozyckwtfqjonsxe
|
||||
muruvapdgfxlzyckwtfqjojsie
|
||||
wtruvapdghxlzyckvtfqjonsie
|
||||
mbruvapdghxlzyckysfqjxnsie
|
||||
mbruvrpdghxczyckktfqjonsie
|
||||
mbquvapdghxlryckwtfqjonsne
|
||||
mbruvapdghflzycvwtfqjpnsie
|
||||
mbruvapughclzyckwtfqjonsin
|
||||
mbrhvapdghxlpyckwtfqjonsre
|
||||
mbruvapdgtxlzyckwtfqjoosit
|
||||
mbrupapnghxhzyckwtfqjonsie
|
||||
mmvuvapdvhxlzyckwtfqjonsie
|
||||
mbruvaptghxlzyckwtfqjotsse
|
||||
mgruvapvghxlzyckwtfqjonsix
|
||||
mbrupapdghxszyckwtfqjunsie
|
||||
mbruvkpdghelzyckwtfqjpnsie
|
||||
mbruvrrdghjlzyckwtfqjonsie
|
||||
mbruvapdghnlzyckwtfkjonsze
|
||||
mbruvwpdghxlzyckwtfqhoysie
|
||||
mbrsvapdfhxlzyckwtfqjobsie
|
||||
mbruvapdgexezymkwtfqjonsie
|
||||
ybruvapdghxlzyckwtfqxonsiw
|
||||
mrruvapdghxdzyckwtfqjossie
|
||||
mbruvapdghtlzyckwtfqconsiu
|
||||
mbrpvapdghxlzlckwpfqjonsie
|
||||
mbruvjpdghslzyckwtfqjjnsie
|
||||
mhruvapoghxlzyckwtfvjonsie
|
||||
mbrubqpdghvlzyckwtfqjonsie
|
||||
mbruvapdghxlzackwtfqconsiw
|
||||
mbruvapdgnxlzkckwtfqjdnsie
|
||||
mbrudapgghelzyckwtfqjonsie
|
||||
mbruvapdghxlzlakwbfqjonsie
|
||||
mbpuvapdghxlzyckwtuqjonjie
|
||||
abruvapdghxlzykkwtfqjonzie
|
||||
mbrupupdghxlsyckwtfqjonsie
|
||||
mbrsvupdghxlzyckwtfqjonkie
|
||||
mxruvgpdghxllyckwtfqjonsie
|
||||
mbrnvapdghxlzycbwtfqfonsie
|
||||
mbrbxapdghxlzyckttfqjonsie
|
||||
mbnuvapdghxlzyxkwtmqjonsie
|
||||
mbrfvapdghjlzickwtfqjonsie
|
||||
mbhuvupdghxlzyxkwtfqjonsie
|
||||
mbrcvapdghxluyckwtfqjznsie
|
||||
mbruvapdghxlzyckwofqjoxsiz
|
||||
mbrevapdghxloyckwtfqjonnie
|
||||
mbruvipdghnlzyckwtfqjopsie
|
||||
mbxxvaptghxlzyckwtfqjonsie
|
||||
mbruvcpdghxlztckwtjqjonsie
|
||||
mqruvlpdghxlzyckotfqjonsie
|
||||
mbruvapdgqxlzyckwtfqjpvsie
|
||||
mbruvapdgvxlzyjkwtfqjbnsie
|
||||
mbruvapdghxlgyckwtfqcocsie
|
||||
mbruvapdghxkwyckwtfqjoqsie
|
||||
mbrgvavdghxlzyckwxfqjonsie
|
||||
qbruqapdgvxlzyckwtfqjonsie
|
||||
mbauvapdghxlzgckwtfqjunsie
|
||||
mbruvapdgdxluyckwtfqjoosie
|
||||
mbruvapdghxlzykkwtfqwobsie
|
||||
mbruvapdghxlzhcnwtfqjonqie
|
||||
mbruvapdghxlzycbhmfqjonsie
|
||||
mbruvapdghxluyczwtfqjontie
|
||||
mbruvapnghxlzyckwnfqjonbie
|
||||
moruvapdghxlzcckwtfqponsie
|
||||
mbruvapfgxxlzyckwtfqjunsie
|
||||
mbruvapdghxlryckvtfejonsie
|
||||
mbrzvapdghxlzvcbwtfqjonsie
|
||||
mbruvapdgqxlzyckwcfqjonsce
|
||||
abruvupdrhxlzyckwtfqjonsie
|
||||
mbrubaptghxlzyckwtfqjondie
|
||||
mgruvapdgpxlzyckwtfijonsie
|
||||
mbruvapdghxczlckwtfujonsie
|
||||
mbruvapdgmmlzyckwtfqjonsir
|
||||
mbruvapdhhxltyckwtfdjonsie
|
||||
mbruvapdghxlzyckwtfdjjnste
|
||||
mbrdvzpdghxlcyckwtfqjonsie
|
||||
mbruvapdghxlzyckwtnqbonsim
|
||||
mbrovapdghxlzyckwtfpjousie
|
||||
mymuvapdghxlzyjkwtfqjonsie
|
||||
mbpuvapdghxlzyckwtfljcnsie
|
||||
mbrxvapdghxlzyclwtfqjonpie
|
||||
mbrueapdghxlzyckwtfqjopsia
|
||||
mbruvapdghxlzycdwtfqjbfsie
|
||||
tbruvavdghxlzyckwtmqjonsie
|
||||
mbduvapdghxlzyckwrfqjrnsie
|
||||
mkrsvapughxlzyckwtfqjonsie
|
||||
mbruvapdghylzyckwtfqtolsie
|
||||
mgruvapdglxldyckwtfqjonsie
|
||||
mbrunapdghclzyckwtfqjonsiy
|
||||
mbruvapdgrxlxyckwtfgjonsie
|
||||
mbruvapdghxpzbckftfqjonsie
|
||||
mbruvcpdghxyzyckotfqjonsie
|
||||
mbruvapdghxlsyckwtfqcqnsie
|
||||
mbruvapdghxlzzckwtfqjonskf
|
||||
mbruvppdghxlzfckwtfqjgnsie
|
||||
mbhuvapdghxlzytkwtfqjonoie
|
||||
mbruvapdghxlzvrkwtfqjjnsie
|
||||
mbmuvapdghxuzyckwtfqjonsze
|
||||
mbruvapdghnlzycnwtfqjonsil
|
||||
mbruvapdgholzyckitfqjonsia
|
||||
mbruxapdghxlmyckwtfqbonsie
|
||||
mbauvapdgholzyckwtfqjolsie
|
||||
mbruvapdghxlzyckwtfqjotslq
|
||||
dbrutapdghxlzyckwtfqjonsiv
|
||||
mbruvapdzhxlyyckwtfbjonsie
|
||||
mmruaapsghxlzyckwtfqjonsie
|
||||
mbruvaldgqxqzyckwtfqjonsie
|
||||
mbruvaodghxdzyjkwtfqjonsie
|
||||
mbrcmatdghxlzyckwtfqjonsie
|
||||
mbrqvapdgtxlzycewtfqjonsie
|
||||
mjruvapdghzlzyckwtfqjonrie
|
||||
mbruvapdghxopcckwtfqjonsie
|
||||
mbruvapdghxszycwwtfqjoqsie
|
||||
mbruvapdgoxezyckwtjqjonsie
|
||||
@@ -1,35 +1,36 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// std::vector<std::string> parseFile(std::string fileName) {
|
||||
// std::cout << "test1" << fileName << std::endl;
|
||||
bool isRepeat(std::string line, int repeats) {
|
||||
for (char c = 'a'; c <= 'z'; ++c) {
|
||||
int count = 0;
|
||||
for (size_t i = 0; i < line.size(); ++i) {
|
||||
if (line[i] == c)
|
||||
++count;
|
||||
}
|
||||
if (count == repeats)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// std::vector<std::string> output;
|
||||
// std::cout << "test2" << fileName << std::endl;
|
||||
|
||||
// std::fstream stream(fileName);
|
||||
// std::cout << "Reading: " << fileName << " into array" << std::endl;
|
||||
|
||||
// for (std::string line; std::getline(stream, line); )
|
||||
// output.push_back(line);
|
||||
// return output;
|
||||
// }
|
||||
int checkSum(std::string fileName) {
|
||||
std::fstream input(fileName);
|
||||
std::string line;
|
||||
int doubles = 0;
|
||||
int triples = 0;
|
||||
|
||||
while (!input.eof()) {
|
||||
std::getline(input, line);
|
||||
if (isRepeat(line, 2))
|
||||
++doubles;
|
||||
if (isRepeat(line, 3))
|
||||
++triples;
|
||||
}
|
||||
return doubles * triples;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
std::cout << "WTF WHY ISNT THIS OUTPUTTING" << std::endl;
|
||||
|
||||
std::vector<std::string> lines; // = parseFile("input.txt");// *(argv + 1));
|
||||
std::fstream stream("input.txt");
|
||||
|
||||
// std::string line;
|
||||
// for (std::string line; std::getline(stream, line); ) {}
|
||||
// lines.push_back(line);
|
||||
// for (unsigned int i = 0; i < lines.size(); i++)
|
||||
// std::cout << lines[i] << std::endl;
|
||||
} catch (const std::string &e) {
|
||||
std::cout << e << std::endl;
|
||||
}
|
||||
std::cout << "Found: " << checkSum("input.txt") << std::endl;
|
||||
}
|
||||
|
||||
BIN
AdventOfCode2018/2ndDay/challenge2/a.out
Executable file
BIN
AdventOfCode2018/2ndDay/challenge2/a.out
Executable file
Binary file not shown.
15
AdventOfCode2018/2ndDay/challenge2/challenge.txt
Normal file
15
AdventOfCode2018/2ndDay/challenge2/challenge.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
--- Part Two ---
|
||||
Confident that your list of box IDs is complete, you're ready to find the boxes full of prototype fabric.
|
||||
|
||||
The boxes will have IDs which differ by exactly one character at the same position in both strings. For example, given the following box IDs:
|
||||
|
||||
abcde
|
||||
fghij
|
||||
klmno
|
||||
pqrst
|
||||
fguij
|
||||
axcye
|
||||
wvxyz
|
||||
The IDs abcde and axcye are close, but they differ by two characters (the second and fourth). However, the IDs fghij and fguij differ by exactly one character, the third (h and u). Those must be the correct boxes.
|
||||
|
||||
What letters are common between the two correct box IDs? (In the example above, this is found by removing the differing character from either ID, producing fgij.)
|
||||
250
AdventOfCode2018/2ndDay/challenge2/input.txt
Normal file
250
AdventOfCode2018/2ndDay/challenge2/input.txt
Normal file
@@ -0,0 +1,250 @@
|
||||
ybruvapdgixszyckwtfqjonsie
|
||||
mbruvapxghslyyckwtfqjonsie
|
||||
mbruvapdghslzyckwtkujonsie
|
||||
rwruvapdghxlzyckwtfqjcnsie
|
||||
obruvapdgtxlzyckwtfqionsie
|
||||
lbruvapdghxqzyckwtfqjfnsie
|
||||
mbrunapdghxlzyccatfqjonsie
|
||||
mbruvapdghxlzyokltfqjdnsie
|
||||
ybruvapdghxlzmckwtfqjmnsie
|
||||
mbruwaadghxdzyckwtfqjonsie
|
||||
muruvapdghxlzyckvtfqjonsim
|
||||
mbruvapdghxlkyckwtxqjonjie
|
||||
mbruvaqdghxlzyckwtfqjrnnie
|
||||
mwruvapdghdlzyckttfqjonsie
|
||||
mbruvapdgtelzyckwxfqjonsie
|
||||
mbruvapdohxlzvckwtfqjonhie
|
||||
mbrugapdgbxlzyckwtfqjynsie
|
||||
mbruvapdghxlzyckwtlqjonjiu
|
||||
mbruvapwghxlzyckwafqjonbie
|
||||
wbruvapdghxlhyckwtfqjonsii
|
||||
mbruvapdghxlzyckwtcqnonsiq
|
||||
mbyuvapighxlzybkwtfqjonsie
|
||||
mbrrvapdghxvzyckwtfqjonsio
|
||||
mhruvapdghrlzyckwtfzjonsie
|
||||
mtruvapvghxlzyckwtfnjonsie
|
||||
mmrlhapdghxlzyckwtfqjonsie
|
||||
mbruvapdgpxlzyjkwtfqjovsie
|
||||
mbrucapdghxlzymkwtzqjonsie
|
||||
mbeuvafdghxlzyckwtfqjonwie
|
||||
mbruvapcghxlayckwtfqjonsii
|
||||
mbruvabdghxlzyckwtfqyansie
|
||||
mbruvjpdghxlzyckwtfqgfnsie
|
||||
lbruvapdghxlzyckwtfqjonriv
|
||||
mbrupapdghxlzycjwtfqronsie
|
||||
mbpuvapdthxlzymkwtfqjonsie
|
||||
mbiuvapdgixlzyckwxfqjonsie
|
||||
mbruvapdghxyzyckwtfcjonsbe
|
||||
mbrurapkghxlzyckwtfqjonzie
|
||||
mbrufapdrhxlzyciwtfqjonsie
|
||||
mbruvapdghxlzbckwtfqjoisae
|
||||
ubruhapdghxlzuckwtfqjonsie
|
||||
mbruvapdjhulzyckwtfqjonshe
|
||||
mbruwapdgyxlzyckntfqjonsie
|
||||
mwruvapdghplzyckwtfqjonsme
|
||||
mbruvapjghtlzyckwtfqgonsie
|
||||
pbruvapdghhlzyckwtfrjonsie
|
||||
mbruvgpdihxqzyckwtfqjonsie
|
||||
mbruvahdohxlzyckwtfijonsie
|
||||
ibuuvapdghxlzyckwtfqjofsie
|
||||
mbruvandghxlzyckwtfqjrnxie
|
||||
mbrjvlpdghxlzyckwgfqjonsie
|
||||
mbruvapogfxlzyckotfqjonsie
|
||||
mbruvrpdghxlzyckutfejonsie
|
||||
mbruvbpdghxlzyhkwtfqjonsip
|
||||
mbruvapdghxlzyckmnfqjensie
|
||||
mbruvapdghvlzyckwtfqjowsix
|
||||
mbruvakdgholzwckwtfqjonsie
|
||||
mbruvapdghxlzackwtfqconsae
|
||||
mbruvapdghxlzyqvwtfqjlnsie
|
||||
mprrvapdgfxlzyckwtfqjonsie
|
||||
mbrunacdghxlhyckwtfqjonsie
|
||||
obruvapdgsxlzyckwtfqjonvie
|
||||
murcvapdghslzyckwtfqjonsie
|
||||
mbruvapdghxlzyzkwmftjonsie
|
||||
mbrwvapdgtvlzyckwtfqjonsie
|
||||
mbxuvapdghxlzqcnwtfqjonsie
|
||||
mbruvaddghxboyckwtfqjonsie
|
||||
mhruvwndghxlzyckwtfqjonsie
|
||||
mbrdvapdghxlzyckwmpqjonsie
|
||||
mbruvapdgyxlzyckizfqjonsie
|
||||
mbruvapdghxlzlckwtfqeowsie
|
||||
mbruvbpdgrxlzyckwtfqjonsxe
|
||||
mbruqapoghxlzyckwtvqjonsie
|
||||
mbouhapdghmlzyckwtfqjonsie
|
||||
mbruvapjghxidyckwtfqjonsie
|
||||
mbsuvapkghxlkyckwtfqjonsie
|
||||
mbruvlpdghxlzycrwtfqjonsis
|
||||
mcrueapdghxlzyckwtfqjynsie
|
||||
muruvapngbxlzyckwtfqjonsie
|
||||
mbruvapdghxlzycawtfyjojsie
|
||||
mbruvbpdghxczyjkwtfqjonsie
|
||||
ybduvapdghxnzyckwtfqjonsie
|
||||
mbruvbpdghxlzyckwtfbjousie
|
||||
mbouvapdghxlzycbwtfqponsie
|
||||
mbruvaedghplzycgwtfqjonsie
|
||||
mbrhvapdghxlzyckytfqjgnsie
|
||||
mbruvapdqbxleyckwtfqjonsie
|
||||
mbruvapddhhldyckwtfqjonsie
|
||||
mbruvapdghxlwrckwtfqjondie
|
||||
mbruvapdmhxlzyckwtfqkonsve
|
||||
xbbuvapdghxlzyckwtfkjonsie
|
||||
mbruvapdghxlzyckwcfqjunkie
|
||||
mbruvapdghxlzyckwtfqxonfib
|
||||
mbrtvapkghxlzyckwtfqeonsie
|
||||
mbruvazdghxldymkwtfqjonsie
|
||||
kbruvapddhxlzfckwtfqjonsie
|
||||
mbouvapdghxlpyckwtfqjoosie
|
||||
mbauvapdghxlzyckwtfqjszsie
|
||||
mbruvapdghtlzyckntfqtonsie
|
||||
mbruvipdggxlzbckwtfqjonsie
|
||||
mbruqapdghrlzyckwtfqjznsie
|
||||
myruvacdghxlzyckwifqjonsie
|
||||
mbruvapdghxlzuckwtfkjocsie
|
||||
mwjuvapdghxlzyckwtfqjonsxe
|
||||
mbruvapxghxlzickwtfqjobsie
|
||||
mbrupapdghxtlyckwtfqjonsie
|
||||
meruvapdjjxlzyckwtfqjonsie
|
||||
mbruvkodghxlzyckwofqjonsie
|
||||
mbruvapdgexlzyckwtgkjonsie
|
||||
mbruvapwghxlzyckwtcqjonsiw
|
||||
mbruvapdghxlzykkwtfqtoxsie
|
||||
mbruvapdahxlzycgwtfwjonsie
|
||||
mbruvapdgwxlhyckhtfqjonsie
|
||||
mbruvapbghxlzycbhmfqjonsie
|
||||
mbruvapdghxvzyzkwtfqjonsin
|
||||
mbrcvapdqhxlzyckwyfqjonsie
|
||||
zbruvaxdghxlzyckwgfqjonsie
|
||||
mtruvapdghxlilckwtfqjonsie
|
||||
bbruvapdghxlzyckwtfmjonsxe
|
||||
mbruvajdghxlzyckwtfqfwnsie
|
||||
mbruvapdgkxlzyckwtfqionpie
|
||||
rbruvapdghxlryckwdfqjonsie
|
||||
mbruvandghxlzyckwmfvjonsie
|
||||
mbruvahdghxlzeckwtfqjonsme
|
||||
mbruvnpcghxlzyckwtfqjobsie
|
||||
mbruvapdghqlzyckwtfbjonsiy
|
||||
mbruvavdghxlzyckwufqjodsie
|
||||
mbruvapdghxlzyckwtfzmovsie
|
||||
mbruvlpdghxuzyckwtfqjoesie
|
||||
mbruvopdghxlzycwwtfqjansie
|
||||
obruvapdghglzybkwtfqjonsie
|
||||
mbpuvlpdghxlcyckwtfqjonsie
|
||||
mbruvaidghxlzyckwtfmjonoie
|
||||
mbruvapdihxzzyckwtfqjonsiy
|
||||
mbquvapdghxlzyckwtfqconsme
|
||||
mbruvapdghslzyckqtfqjojsie
|
||||
mbrzdapdghxmzyckwtfqjonsie
|
||||
mwruvapdghxozyckwtfqjonsxe
|
||||
muruvapdgfxlzyckwtfqjojsie
|
||||
wtruvapdghxlzyckvtfqjonsie
|
||||
mbruvapdghxlzyckysfqjxnsie
|
||||
mbruvrpdghxczyckktfqjonsie
|
||||
mbquvapdghxlryckwtfqjonsne
|
||||
mbruvapdghflzycvwtfqjpnsie
|
||||
mbruvapughclzyckwtfqjonsin
|
||||
mbrhvapdghxlpyckwtfqjonsre
|
||||
mbruvapdgtxlzyckwtfqjoosit
|
||||
mbrupapnghxhzyckwtfqjonsie
|
||||
mmvuvapdvhxlzyckwtfqjonsie
|
||||
mbruvaptghxlzyckwtfqjotsse
|
||||
mgruvapvghxlzyckwtfqjonsix
|
||||
mbrupapdghxszyckwtfqjunsie
|
||||
mbruvkpdghelzyckwtfqjpnsie
|
||||
mbruvrrdghjlzyckwtfqjonsie
|
||||
mbruvapdghnlzyckwtfkjonsze
|
||||
mbruvwpdghxlzyckwtfqhoysie
|
||||
mbrsvapdfhxlzyckwtfqjobsie
|
||||
mbruvapdgexezymkwtfqjonsie
|
||||
ybruvapdghxlzyckwtfqxonsiw
|
||||
mrruvapdghxdzyckwtfqjossie
|
||||
mbruvapdghtlzyckwtfqconsiu
|
||||
mbrpvapdghxlzlckwpfqjonsie
|
||||
mbruvjpdghslzyckwtfqjjnsie
|
||||
mhruvapoghxlzyckwtfvjonsie
|
||||
mbrubqpdghvlzyckwtfqjonsie
|
||||
mbruvapdghxlzackwtfqconsiw
|
||||
mbruvapdgnxlzkckwtfqjdnsie
|
||||
mbrudapgghelzyckwtfqjonsie
|
||||
mbruvapdghxlzlakwbfqjonsie
|
||||
mbpuvapdghxlzyckwtuqjonjie
|
||||
abruvapdghxlzykkwtfqjonzie
|
||||
mbrupupdghxlsyckwtfqjonsie
|
||||
mbrsvupdghxlzyckwtfqjonkie
|
||||
mxruvgpdghxllyckwtfqjonsie
|
||||
mbrnvapdghxlzycbwtfqfonsie
|
||||
mbrbxapdghxlzyckttfqjonsie
|
||||
mbnuvapdghxlzyxkwtmqjonsie
|
||||
mbrfvapdghjlzickwtfqjonsie
|
||||
mbhuvupdghxlzyxkwtfqjonsie
|
||||
mbrcvapdghxluyckwtfqjznsie
|
||||
mbruvapdghxlzyckwofqjoxsiz
|
||||
mbrevapdghxloyckwtfqjonnie
|
||||
mbruvipdghnlzyckwtfqjopsie
|
||||
mbxxvaptghxlzyckwtfqjonsie
|
||||
mbruvcpdghxlztckwtjqjonsie
|
||||
mqruvlpdghxlzyckotfqjonsie
|
||||
mbruvapdgqxlzyckwtfqjpvsie
|
||||
mbruvapdgvxlzyjkwtfqjbnsie
|
||||
mbruvapdghxlgyckwtfqcocsie
|
||||
mbruvapdghxkwyckwtfqjoqsie
|
||||
mbrgvavdghxlzyckwxfqjonsie
|
||||
qbruqapdgvxlzyckwtfqjonsie
|
||||
mbauvapdghxlzgckwtfqjunsie
|
||||
mbruvapdgdxluyckwtfqjoosie
|
||||
mbruvapdghxlzykkwtfqwobsie
|
||||
mbruvapdghxlzhcnwtfqjonqie
|
||||
mbruvapdghxlzycbhmfqjonsie
|
||||
mbruvapdghxluyczwtfqjontie
|
||||
mbruvapnghxlzyckwnfqjonbie
|
||||
moruvapdghxlzcckwtfqponsie
|
||||
mbruvapfgxxlzyckwtfqjunsie
|
||||
mbruvapdghxlryckvtfejonsie
|
||||
mbrzvapdghxlzvcbwtfqjonsie
|
||||
mbruvapdgqxlzyckwcfqjonsce
|
||||
abruvupdrhxlzyckwtfqjonsie
|
||||
mbrubaptghxlzyckwtfqjondie
|
||||
mgruvapdgpxlzyckwtfijonsie
|
||||
mbruvapdghxczlckwtfujonsie
|
||||
mbruvapdgmmlzyckwtfqjonsir
|
||||
mbruvapdhhxltyckwtfdjonsie
|
||||
mbruvapdghxlzyckwtfdjjnste
|
||||
mbrdvzpdghxlcyckwtfqjonsie
|
||||
mbruvapdghxlzyckwtnqbonsim
|
||||
mbrovapdghxlzyckwtfpjousie
|
||||
mymuvapdghxlzyjkwtfqjonsie
|
||||
mbpuvapdghxlzyckwtfljcnsie
|
||||
mbrxvapdghxlzyclwtfqjonpie
|
||||
mbrueapdghxlzyckwtfqjopsia
|
||||
mbruvapdghxlzycdwtfqjbfsie
|
||||
tbruvavdghxlzyckwtmqjonsie
|
||||
mbduvapdghxlzyckwrfqjrnsie
|
||||
mkrsvapughxlzyckwtfqjonsie
|
||||
mbruvapdghylzyckwtfqtolsie
|
||||
mgruvapdglxldyckwtfqjonsie
|
||||
mbrunapdghclzyckwtfqjonsiy
|
||||
mbruvapdgrxlxyckwtfgjonsie
|
||||
mbruvapdghxpzbckftfqjonsie
|
||||
mbruvcpdghxyzyckotfqjonsie
|
||||
mbruvapdghxlsyckwtfqcqnsie
|
||||
mbruvapdghxlzzckwtfqjonskf
|
||||
mbruvppdghxlzfckwtfqjgnsie
|
||||
mbhuvapdghxlzytkwtfqjonoie
|
||||
mbruvapdghxlzvrkwtfqjjnsie
|
||||
mbmuvapdghxuzyckwtfqjonsze
|
||||
mbruvapdghnlzycnwtfqjonsil
|
||||
mbruvapdgholzyckitfqjonsia
|
||||
mbruxapdghxlmyckwtfqbonsie
|
||||
mbauvapdgholzyckwtfqjolsie
|
||||
mbruvapdghxlzyckwtfqjotslq
|
||||
dbrutapdghxlzyckwtfqjonsiv
|
||||
mbruvapdzhxlyyckwtfbjonsie
|
||||
mmruaapsghxlzyckwtfqjonsie
|
||||
mbruvaldgqxqzyckwtfqjonsie
|
||||
mbruvaodghxdzyjkwtfqjonsie
|
||||
mbrcmatdghxlzyckwtfqjonsie
|
||||
mbrqvapdgtxlzycewtfqjonsie
|
||||
mjruvapdghzlzyckwtfqjonrie
|
||||
mbruvapdghxopcckwtfqjonsie
|
||||
mbruvapdghxszycwwtfqjoqsie
|
||||
mbruvapdgoxezyckwtjqjonsie
|
||||
50
AdventOfCode2018/2ndDay/challenge2/main.cpp
Normal file
50
AdventOfCode2018/2ndDay/challenge2/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
std::string equalLetters(std::string fileName) {
|
||||
std::fstream input(fileName);
|
||||
std::string line;
|
||||
std::string a;
|
||||
std::string b;
|
||||
std::string answer;
|
||||
std::vector<std::string> lines;
|
||||
|
||||
while (!input.eof()) {
|
||||
std::getline(input, line);
|
||||
lines.push_back(line);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
int count = 0;
|
||||
a = lines[i];
|
||||
|
||||
for (size_t j = i + 1; j < lines.size(); ++j) {
|
||||
b = lines[j];
|
||||
count = 0;
|
||||
|
||||
for (size_t k = 0; k < a.size(); ++k) {
|
||||
if (a[k] != b[k])
|
||||
++count;
|
||||
if (count > 1)
|
||||
break;
|
||||
}
|
||||
if (count == 1)
|
||||
break;
|
||||
}
|
||||
if (count == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < a.size(); ++i) {
|
||||
if (a[i] == b[i])
|
||||
answer += a[i];
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "Found: " << equalLetters("input.txt") << std::endl;
|
||||
}
|
||||
107
AdventOfCode2018/3rdDay/challenge1/Program.cs
Normal file
107
AdventOfCode2018/3rdDay/challenge1/Program.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace challenge1 {
|
||||
class Program {
|
||||
static string[] Lines {get; set;}
|
||||
static List<Claim> Claims {get; set;}
|
||||
|
||||
static void Main(string[] args) {
|
||||
Claims = new List<Claim>();
|
||||
Console.WriteLine("Reading input.txt");
|
||||
Lines = File.ReadAllLines("./input.txt");
|
||||
foreach (string line in Lines) {
|
||||
Claim current = new Claim(line);
|
||||
Claims.Add(current);
|
||||
current.Print();
|
||||
}
|
||||
Fabric fabric = new Fabric(Claims);
|
||||
Console.WriteLine("Found: " + fabric.CalculateOverlaps() + " overlaps");
|
||||
}
|
||||
|
||||
public static void printArray(string[] arr) {
|
||||
foreach (string str in arr) {
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Claim {
|
||||
public int ID {get; set;}
|
||||
public int X {get; set;}
|
||||
public int Y {get; set;}
|
||||
public int W {get; set;}
|
||||
public int H {get; set;}
|
||||
public string Source {get; set;}
|
||||
|
||||
public Claim(string source) {
|
||||
this.Source = source;
|
||||
ParseSource();
|
||||
}
|
||||
|
||||
private void ParseSource() {
|
||||
Console.WriteLine("Parsing: " + this.Source);
|
||||
string[] source = this.Source.Split('#');
|
||||
string[] idAndRest = source[1].Split('@');
|
||||
this.ID = int.Parse(idAndRest[0]);
|
||||
string[] fromSides = idAndRest[1].Split(',');
|
||||
string[] afterColon = fromSides[1].Split(':');
|
||||
this.X = int.Parse(fromSides[0]);
|
||||
this.Y = int.Parse(afterColon[0]);
|
||||
string[] dimensions = afterColon[1].Split('x');
|
||||
this.W = int.Parse(dimensions[0]);
|
||||
this.H = int.Parse(dimensions[1]);
|
||||
}
|
||||
|
||||
public void Print() {
|
||||
Console.WriteLine("Claim ID: " + this.ID);
|
||||
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
|
||||
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
|
||||
Console.WriteLine("Parsed from source: " + this.Source);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
class Fabric {
|
||||
public List<Claim> Claims;
|
||||
|
||||
private int[,] Board;
|
||||
|
||||
public Fabric(List<Claim> claims) {
|
||||
this.Claims = claims;
|
||||
this.Board = new int[10000, 10000];
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
for (int j = 0; j < 10000; j++) {
|
||||
Board[i, j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int CalculateOverlaps() {
|
||||
int overlaps = 0;
|
||||
|
||||
int i = 0;
|
||||
foreach (Claim claim in this.Claims) {
|
||||
Console.WriteLine("Processing claim ID: " + claim.ID);
|
||||
|
||||
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
||||
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
||||
Board[x, y]++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
for (i = 0; i < 10000; i++) {
|
||||
for (int j = 0; j < 10000; j++) {
|
||||
if (Board[i,j] > 1) overlaps++;
|
||||
}
|
||||
}
|
||||
|
||||
return overlaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
AdventOfCode2018/3rdDay/challenge1/challenge.txt
Normal file
40
AdventOfCode2018/3rdDay/challenge1/challenge.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
--- Day 3: No Matter How You Slice It ---
|
||||
The Elves managed to locate the chimney-squeeze prototype fabric for Santa's suit (thanks to someone who helpfully wrote its box IDs on the wall of the warehouse in the middle of the night). Unfortunately, anomalies are still affecting them - nobody can even agree on how to cut the fabric.
|
||||
|
||||
The whole piece of fabric they're working on is a very large square - at least 1000 inches on each side.
|
||||
|
||||
Each Elf has made a claim about which area of fabric would be ideal for Santa's suit. All claims have an ID and consist of a single rectangle with edges parallel to the edges of the fabric. Each claim's rectangle is defined as follows:
|
||||
|
||||
The number of inches between the left edge of the fabric and the left edge of the rectangle.
|
||||
The number of inches between the top edge of the fabric and the top edge of the rectangle.
|
||||
The width of the rectangle in inches.
|
||||
The height of the rectangle in inches.
|
||||
A claim like #123 @ 3,2: 5x4 means that claim ID 123 specifies a rectangle 3 inches from the left edge, 2 inches from the top edge, 5 inches wide, and 4 inches tall. Visually, it claims the square inches of fabric represented by # (and ignores the square inches of fabric represented by .) in the diagram below:
|
||||
|
||||
...........
|
||||
...........
|
||||
...#####...
|
||||
...#####...
|
||||
...#####...
|
||||
...#####...
|
||||
...........
|
||||
...........
|
||||
...........
|
||||
The problem is that many of the claims overlap, causing two or more claims to cover part of the same areas. For example, consider the following claims:
|
||||
|
||||
#1 @ 1,3: 4x4
|
||||
#2 @ 3,1: 4x4
|
||||
#3 @ 5,5: 2x2
|
||||
Visually, these claim the following areas:
|
||||
|
||||
........
|
||||
...2222.
|
||||
...2222.
|
||||
.11XX22.
|
||||
.11XX22.
|
||||
.111133.
|
||||
.111133.
|
||||
........
|
||||
The four square inches marked with X are claimed by both 1 and 2. (Claim 3, while adjacent to the others, does not overlap either of them.)
|
||||
|
||||
If the Elves all proceed with their own plans, none of them will have enough fabric. How many square inches of fabric are within two or more claims?
|
||||
8
AdventOfCode2018/3rdDay/challenge1/challenge1.csproj
Normal file
8
AdventOfCode2018/3rdDay/challenge1/challenge1.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
1283
AdventOfCode2018/3rdDay/challenge1/input.txt
Normal file
1283
AdventOfCode2018/3rdDay/challenge1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
115
AdventOfCode2018/3rdDay/challenge2/Program.cs
Normal file
115
AdventOfCode2018/3rdDay/challenge2/Program.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace challenge2 {
|
||||
class Program {
|
||||
static string[] Lines {get; set;}
|
||||
static List<Claim> Claims {get; set;}
|
||||
|
||||
static void Main(string[] args) {
|
||||
Claims = new List<Claim>();
|
||||
Console.WriteLine("Reading input.txt");
|
||||
Lines = File.ReadAllLines("./input.txt");
|
||||
foreach (string line in Lines) {
|
||||
Claim current = new Claim(line);
|
||||
Claims.Add(current);
|
||||
current.Print();
|
||||
}
|
||||
Fabric fabric = new Fabric(Claims);
|
||||
Console.WriteLine("Found ID: " + fabric.CalculateOverlaps());
|
||||
}
|
||||
|
||||
public static void printArray(string[] arr) {
|
||||
foreach (string str in arr) {
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Claim {
|
||||
public int ID {get; set;}
|
||||
public int X {get; set;}
|
||||
public int Y {get; set;}
|
||||
public int W {get; set;}
|
||||
public int H {get; set;}
|
||||
public string Source {get; set;}
|
||||
|
||||
public Claim(string source) {
|
||||
this.Source = source;
|
||||
ParseSource();
|
||||
}
|
||||
|
||||
private void ParseSource() {
|
||||
Console.WriteLine("Parsing: " + this.Source);
|
||||
string[] source = this.Source.Split('#');
|
||||
string[] idAndRest = source[1].Split('@');
|
||||
this.ID = int.Parse(idAndRest[0]);
|
||||
string[] fromSides = idAndRest[1].Split(',');
|
||||
string[] afterColon = fromSides[1].Split(':');
|
||||
this.X = int.Parse(fromSides[0]);
|
||||
this.Y = int.Parse(afterColon[0]);
|
||||
string[] dimensions = afterColon[1].Split('x');
|
||||
this.W = int.Parse(dimensions[0]);
|
||||
this.H = int.Parse(dimensions[1]);
|
||||
}
|
||||
|
||||
public void Print() {
|
||||
Console.WriteLine("Claim ID: " + this.ID);
|
||||
Console.WriteLine("X, Y: " + this.X + ',' + this.Y);
|
||||
Console.WriteLine("Dimensions: " + this.W + 'x' + this.H);
|
||||
Console.WriteLine("Parsed from source: " + this.Source);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
class Fabric {
|
||||
public List<Claim> Claims;
|
||||
|
||||
private int[,] Board;
|
||||
|
||||
public Fabric(List<Claim> claims) {
|
||||
this.Claims = claims;
|
||||
this.Board = new int[10000, 10000];
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
for (int j = 0; j < 10000; j++) {
|
||||
Board[i, j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int CalculateOverlaps() {
|
||||
int overlaps = 0;
|
||||
|
||||
foreach (Claim claim in this.Claims) {
|
||||
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
||||
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
||||
Board[x, y]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Claim claim in this.Claims) {
|
||||
bool isValid = true;
|
||||
Console.WriteLine("Processing claim ID: " + claim.ID);
|
||||
|
||||
for (int x = claim.X; x < claim.X + claim.W; x++) {
|
||||
for (int y = claim.Y; y < claim.Y + claim.H; y++) {
|
||||
if(this.Board[x,y] != 1) {
|
||||
isValid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isValid) break;
|
||||
}
|
||||
if (isValid) {
|
||||
overlaps = claim.ID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return overlaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
AdventOfCode2018/3rdDay/challenge2/challenge.txt
Normal file
11
AdventOfCode2018/3rdDay/challenge2/challenge.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
Your puzzle answer was 109143.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: *
|
||||
|
||||
--- Part Two ---
|
||||
Amidst the chaos, you notice that exactly one claim doesn't overlap by even a single square inch of fabric with any other claim. If you can somehow draw attention to it, maybe the Elves will be able to make Santa's suit after all!
|
||||
|
||||
For example, in the claims above, only claim 3 is intact after all claims are made.
|
||||
|
||||
What is the ID of the only claim that doesn't overlap?
|
||||
8
AdventOfCode2018/3rdDay/challenge2/challenge2.csproj
Normal file
8
AdventOfCode2018/3rdDay/challenge2/challenge2.csproj
Normal file
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
1283
AdventOfCode2018/3rdDay/challenge2/input.txt
Normal file
1283
AdventOfCode2018/3rdDay/challenge2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
37
AdventOfCode2018/4thDay/challenge1/.vscode/settings.json
vendored
Normal file
37
AdventOfCode2018/4thDay/challenge1/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"tuple": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
||||
BIN
AdventOfCode2018/4thDay/challenge1/a.out
Executable file
BIN
AdventOfCode2018/4thDay/challenge1/a.out
Executable file
Binary file not shown.
49
AdventOfCode2018/4thDay/challenge1/challenge.txt
Executable file
49
AdventOfCode2018/4thDay/challenge1/challenge.txt
Executable file
@@ -0,0 +1,49 @@
|
||||
--- Day 4: Repose Record ---
|
||||
You've sneaked into another supply closet - this time, it's across from the prototype suit manufacturing lab. You need to sneak inside and fix the issues with the suit, but there's a guard stationed outside the lab, so this is as close as you can safely get.
|
||||
|
||||
As you search the closet for anything that might help, you discover that you're not the first person to want to sneak in. Covering the walls, someone has spent an hour starting every midnight for the past few months secretly observing this guard post! They've been writing down the ID of the one guard on duty that night - the Elves seem to have decided that one guard was enough for the overnight shift - as well as when they fall asleep or wake up while at their post (your puzzle input).
|
||||
|
||||
For example, consider the following records, which have already been organized into chronological order:
|
||||
|
||||
[1518-11-01 00:00] Guard #10 begins shift
|
||||
[1518-11-01 00:05] falls asleep
|
||||
[1518-11-01 00:25] wakes up
|
||||
[1518-11-01 00:30] falls asleep
|
||||
[1518-11-01 00:55] wakes up
|
||||
[1518-11-01 23:58] Guard #99 begins shift
|
||||
[1518-11-02 00:40] falls asleep
|
||||
[1518-11-02 00:50] wakes up
|
||||
[1518-11-03 00:05] Guard #10 begins shift
|
||||
[1518-11-03 00:24] falls asleep
|
||||
[1518-11-03 00:29] wakes up
|
||||
[1518-11-04 00:02] Guard #99 begins shift
|
||||
[1518-11-04 00:36] falls asleep
|
||||
[1518-11-04 00:46] wakes up
|
||||
[1518-11-05 00:03] Guard #99 begins shift
|
||||
[1518-11-05 00:45] falls asleep
|
||||
[1518-11-05 00:55] wakes up
|
||||
Timestamps are written using year-month-day hour:minute format. The guard falling asleep or waking up is always the one whose shift most recently started. Because all asleep/awake times are during the midnight hour (00:00 - 00:59), only the minute portion (00 - 59) is relevant for those events.
|
||||
|
||||
Visually, these records show that the guards are asleep at these times:
|
||||
|
||||
Date ID Minute
|
||||
000000000011111111112222222222333333333344444444445555555555
|
||||
012345678901234567890123456789012345678901234567890123456789
|
||||
11-01 #10 .....####################.....#########################.....
|
||||
11-02 #99 ........................................##########..........
|
||||
11-03 #10 ........................#####...............................
|
||||
11-04 #99 ....................................##########..............
|
||||
11-05 #99 .............................................##########.....
|
||||
The columns are Date, which shows the month-day portion of the relevant day; ID, which shows the guard on duty that day; and Minute, which shows the minutes during which the guard was asleep within the midnight hour. (The Minute column's header shows the minute's ten's digit in the first row and the one's digit in the second row.) Awake is shown as ., and asleep is shown as #.
|
||||
|
||||
Note that guards count as asleep on the minute they fall asleep, and they count as awake on the minute they wake up. For example, because Guard #10 wakes up at 00:25 on 1518-11-01, minute 25 is marked as awake.
|
||||
|
||||
If you can figure out the guard most likely to be asleep at a specific time, you might be able to trick that guard into working tonight so you can have the best chance of sneaking in. You have two strategies for choosing the best guard/minute combination.
|
||||
|
||||
Strategy 1: Find the guard that has the most minutes asleep. What minute does that guard spend asleep the most?
|
||||
|
||||
In the example above, Guard #10 spent the most minutes asleep, a total of 50 minutes (20+25+5), while Guard #99 only slept for a total of 30 minutes (10+10+10). Guard #10 was asleep most during minute 24 (on two days, whereas any other minute the guard was asleep was only seen on one day).
|
||||
|
||||
While this example listed the entries in chronological order, your entries are in the order you found them. You'll need to organize them before they can be analyzed.
|
||||
|
||||
What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 10 * 24 = 240.)
|
||||
71
AdventOfCode2018/4thDay/challenge1/index.js
Normal file
71
AdventOfCode2018/4thDay/challenge1/index.js
Normal file
@@ -0,0 +1,71 @@
|
||||
class Guard {
|
||||
constructor (id) {
|
||||
this.id = id;
|
||||
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
|
||||
this.fellAsleepAt = null;
|
||||
}
|
||||
|
||||
sleep (fellAsleepAt) {
|
||||
this.fellAsleepAt = fellAsleepAt;
|
||||
}
|
||||
|
||||
awake (awokeAt) {
|
||||
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
|
||||
this.minutesAsleep[i] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
get totalSleepMinutes () {
|
||||
return this.minutesAsleep.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
get sleepiestMinute () {
|
||||
return this.minutesAsleep
|
||||
.map((value, index) => ({ index, value }))
|
||||
.sort((a, b) => b.value - a.value)[0].index;
|
||||
}
|
||||
}
|
||||
|
||||
const sleep = (input) => {
|
||||
const guards = {};
|
||||
const schedule = input
|
||||
.split('\n')
|
||||
.map((x) => x.trim())
|
||||
.sort()
|
||||
.map((x) => {
|
||||
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
|
||||
|
||||
return {
|
||||
minute: +parts[5],
|
||||
message: parts[6],
|
||||
};
|
||||
});
|
||||
|
||||
let currentGuard = null;
|
||||
|
||||
for (let i = 0; i < schedule.length; i++) {
|
||||
const { message, minute } = schedule[i];
|
||||
|
||||
if (/Guard/.test(message)) {
|
||||
const parts = message.match(/Guard #(\d+) begins shift/);
|
||||
const guardId = +parts[1];
|
||||
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
|
||||
|
||||
currentGuard = guards[guardId] = guard;
|
||||
} else if (message === 'falls asleep') {
|
||||
currentGuard.sleep(minute);
|
||||
} else if (message === 'wakes up') {
|
||||
currentGuard.awake(minute);
|
||||
}
|
||||
}
|
||||
const sleepiestGuard = Object
|
||||
.keys(guards)
|
||||
.map((guardId) => guards[guardId])
|
||||
.sort((a, b) => b.totalSleepMinutes - a.totalSleepMinutes)[0];
|
||||
|
||||
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
|
||||
}
|
||||
|
||||
const fs = require('fs');
|
||||
console.log(sleep(fs.readFileSync("input.txt").toString()));
|
||||
|
||||
1000
AdventOfCode2018/4thDay/challenge1/input.txt
Executable file
1000
AdventOfCode2018/4thDay/challenge1/input.txt
Executable file
File diff suppressed because it is too large
Load Diff
180
AdventOfCode2018/4thDay/challenge1/main.cpp
Normal file
180
AdventOfCode2018/4thDay/challenge1/main.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <iomanip>
|
||||
|
||||
enum class State {begin, sleep, awaken};
|
||||
struct Action
|
||||
{
|
||||
State state;
|
||||
int64_t guard_id;
|
||||
};
|
||||
|
||||
struct Event
|
||||
{
|
||||
int64_t month, day, hour, minute;
|
||||
Action action;
|
||||
};
|
||||
|
||||
|
||||
std::istream &operator>>(std::istream &is, Action &action)
|
||||
{
|
||||
std::string element;
|
||||
is >> element;
|
||||
if(element=="Guard")
|
||||
{
|
||||
action.state=State::begin;
|
||||
char c;
|
||||
is >> c >> action.guard_id;
|
||||
}
|
||||
else if(element=="falls")
|
||||
{
|
||||
action.state=State::sleep;
|
||||
}
|
||||
else if(element=="wakes")
|
||||
{
|
||||
action.state=State::awaken;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Invalid input");
|
||||
}
|
||||
std::getline(is,element);
|
||||
return is;
|
||||
}
|
||||
|
||||
std::istream &operator>>(std::istream &is, Event &event)
|
||||
{
|
||||
char c;
|
||||
int64_t year;
|
||||
is >> c;
|
||||
if(is.good())
|
||||
{
|
||||
is >> year >> c >> event.month >> c >> event.day
|
||||
>> event.hour >> c >> event.minute >> c
|
||||
>> event.action;
|
||||
|
||||
if(event.hour==23)
|
||||
{
|
||||
event.minute=0;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Action &action)
|
||||
{
|
||||
switch(action.state)
|
||||
{
|
||||
case State::begin:
|
||||
os << "Guard #" << action.guard_id << " begins shift";
|
||||
break;
|
||||
case State::sleep:
|
||||
os << "falls asleep";
|
||||
break;
|
||||
case State::awaken:
|
||||
os << "wakes up";
|
||||
break;
|
||||
default:
|
||||
os << "What?";
|
||||
break;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Event &event)
|
||||
{
|
||||
os << "[1518-"
|
||||
<< std::setw(2) << std::setfill('0') << event.month << "-"
|
||||
<< std::setw(2) << std::setfill('0') << event.day << " "
|
||||
<< std::setw(2) << std::setfill('0') << event.hour << ":"
|
||||
<< std::setw(2) << std::setfill('0') << event.minute << "] "
|
||||
<< event.action;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::pair<int64_t,int64_t> max_incident(const std::vector<std::pair<int64_t,
|
||||
int64_t>> &incidents)
|
||||
{
|
||||
std::vector<int64_t> sleep_incidents(60,0);
|
||||
for(auto ×: incidents)
|
||||
{
|
||||
for(size_t time=times.first; time<times.second; ++time)
|
||||
{ ++(sleep_incidents[time]); }
|
||||
}
|
||||
|
||||
int64_t max_incidents(0), max_minute(0);
|
||||
for(size_t time=0; time<sleep_incidents.size(); ++time)
|
||||
{
|
||||
if(max_incidents<sleep_incidents[time])
|
||||
{
|
||||
max_incidents=sleep_incidents[time];
|
||||
max_minute=time;
|
||||
}
|
||||
}
|
||||
return std::make_pair(max_incidents,max_minute);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::ifstream infile(argv[1]);
|
||||
std::vector<Event> events(std::istream_iterator<Event>(infile), {});
|
||||
|
||||
std::map<int,std::vector<std::pair<int64_t,int64_t>>> guards;
|
||||
|
||||
int64_t guard_id;
|
||||
int64_t start(-1);
|
||||
for(auto &event: events)
|
||||
{
|
||||
switch(event.action.state)
|
||||
{
|
||||
case State::begin:
|
||||
guard_id=event.action.guard_id;
|
||||
break;
|
||||
case State::sleep:
|
||||
start=event.minute;
|
||||
break;
|
||||
case State::awaken:
|
||||
guards[guard_id].emplace_back(start,event.minute);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t max_time_guard, max_time(0);
|
||||
for(auto &guard: guards)
|
||||
{
|
||||
int64_t total_time(0);
|
||||
for(auto &time: guard.second)
|
||||
{
|
||||
total_time+=time.second-time.first;
|
||||
}
|
||||
if(total_time>max_time)
|
||||
{
|
||||
max_time_guard=guard.first;
|
||||
max_time=total_time;
|
||||
}
|
||||
}
|
||||
|
||||
auto [max_incidents,max_minute]=max_incident(guards[max_time_guard]);
|
||||
std::cout << "Part 1: " << (max_minute*max_time_guard) << "\n";
|
||||
|
||||
std::vector<int64_t> num_incidents(guards.size());
|
||||
int64_t max_guard_incidents(0), max_guard_minute(0), max_guard_id(-1);
|
||||
for(auto &guard: guards)
|
||||
{
|
||||
auto [incidents,minute]=max_incident(guard.second);
|
||||
if(incidents>max_guard_incidents)
|
||||
{
|
||||
max_guard_incidents=incidents;
|
||||
max_guard_minute=minute;
|
||||
max_guard_id=guard.first;
|
||||
}
|
||||
}
|
||||
std::cout << "Part 2: " << (max_guard_id * max_guard_minute) << "\n";
|
||||
}
|
||||
7
AdventOfCode2018/4thDay/challenge2/challenge.txt
Normal file
7
AdventOfCode2018/4thDay/challenge2/challenge.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
--- Part Two ---
|
||||
Strategy 2: Of all guards, which guard is most frequently asleep on the same minute?
|
||||
|
||||
In the example above, Guard #99 spent minute 45 asleep more than any other guard or minute - three times in total. (In all other cases, any guard spent any minute asleep at most twice.)
|
||||
|
||||
What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 99 * 45 = 4455.)
|
||||
|
||||
68
AdventOfCode2018/4thDay/challenge2/index.js
Normal file
68
AdventOfCode2018/4thDay/challenge2/index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
class Guard {
|
||||
constructor (id) {
|
||||
this.id = id;
|
||||
this.minutesAsleep = Array.from({ length: 60 }).map(() => 0);
|
||||
this.fellAsleepAt = null;
|
||||
}
|
||||
|
||||
sleep (fellAsleepAt) {
|
||||
this.fellAsleepAt = fellAsleepAt;
|
||||
}
|
||||
|
||||
awake (awokeAt) {
|
||||
for (let i = this.fellAsleepAt; i < awokeAt; i++) {
|
||||
this.minutesAsleep[i] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
get sleepiestMinute () {
|
||||
return this.minutesAsleep
|
||||
.map((value, index) => ({ index, value }))
|
||||
.sort((a, b) => b.value - a.value)[0].index;
|
||||
}
|
||||
}
|
||||
|
||||
const sleep = (input) => {
|
||||
const guards = {};
|
||||
const schedule = input
|
||||
.split('\n')
|
||||
.map((x) => x.trim())
|
||||
.sort()
|
||||
.map((x) => {
|
||||
const parts = x.match(/\[(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})\] (.*)/);
|
||||
|
||||
return {
|
||||
minute: +parts[5],
|
||||
message: parts[6],
|
||||
};
|
||||
});
|
||||
|
||||
let currentGuard = null;
|
||||
|
||||
for (let i = 0; i < schedule.length; i++) {
|
||||
const { message, minute } = schedule[i];
|
||||
|
||||
if (/Guard/.test(message)) {
|
||||
const parts = message.match(/Guard #(\d+) begins shift/);
|
||||
const guardId = +parts[1];
|
||||
const guard = guards[guardId] ? guards[guardId] : new Guard(guardId);
|
||||
|
||||
currentGuard = guards[guardId] = guard;
|
||||
} else if (message === 'falls asleep') {
|
||||
currentGuard.sleep(minute);
|
||||
} else if (message === 'wakes up') {
|
||||
currentGuard.awake(minute);
|
||||
}
|
||||
}
|
||||
|
||||
const sleepiestGuard = Object
|
||||
.keys(guards)
|
||||
.map((guardId) => guards[guardId])
|
||||
.sort((a, b) => b.minutesAsleep[b.sleepiestMinute] -
|
||||
a.minutesAsleep[a.sleepiestMinute])[0];
|
||||
|
||||
return sleepiestGuard.id * sleepiestGuard.sleepiestMinute;
|
||||
};
|
||||
|
||||
const fs = require('fs');
|
||||
console.log(sleep(fs.readFileSync("input.txt").toString()));
|
||||
1000
AdventOfCode2018/4thDay/challenge2/input.txt
Executable file
1000
AdventOfCode2018/4thDay/challenge2/input.txt
Executable file
File diff suppressed because it is too large
Load Diff
5
AdventOfCode2018/5thDay/.vscode/settings.json
vendored
Normal file
5
AdventOfCode2018/5thDay/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"ostream": "cpp"
|
||||
}
|
||||
}
|
||||
BIN
AdventOfCode2018/5thDay/challenge1/a.out
Executable file
BIN
AdventOfCode2018/5thDay/challenge1/a.out
Executable file
Binary file not shown.
22
AdventOfCode2018/5thDay/challenge1/challenge.txt
Normal file
22
AdventOfCode2018/5thDay/challenge1/challenge.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
--- Day 5: Alchemical Reduction ---
|
||||
You've managed to sneak in to the prototype suit manufacturing lab. The Elves are making decent progress, but are still struggling with the suit's size reduction capabilities.
|
||||
|
||||
While the very latest in 1518 alchemical technology might have solved their problem eventually, you can do better. You scan the chemical composition of the suit's material and discover that it is formed by extremely long polymers (one of which is available as your puzzle input).
|
||||
|
||||
The polymer is formed by smaller units which, when triggered, react with each other such that two adjacent units of the same type and opposite polarity are destroyed. Units' types are represented by letters; units' polarity is represented by capitalization. For instance, r and R are units with the same type but opposite polarity, whereas r and s are entirely different types and do not react.
|
||||
|
||||
For example:
|
||||
|
||||
In aA, a and A react, leaving nothing behind.
|
||||
In abBA, bB destroys itself, leaving aA. As above, this then destroys itself, leaving nothing.
|
||||
In abAB, no two adjacent units are of the same type, and so nothing happens.
|
||||
In aabAAB, even though aa and AA are of the same type, their polarities match, and so nothing happens.
|
||||
Now, consider a larger example, dabAcCaCBAcCcaDA:
|
||||
|
||||
dabAcCaCBAcCcaDA The first 'cC' is removed.
|
||||
dabAaCBAcCcaDA This creates 'Aa', which is removed.
|
||||
dabCBAcCcaDA Either 'cC' or 'Cc' are removed (the result is the same).
|
||||
dabCBAcaDA No further actions can be taken.
|
||||
After all possible reactions, the resulting polymer contains 10 units.
|
||||
|
||||
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.)
|
||||
5
AdventOfCode2018/5thDay/challenge1/index.js
Normal file
5
AdventOfCode2018/5thDay/challenge1/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const day4 = require('./istolethisfromsomeone');
|
||||
const fs = require('fs');
|
||||
|
||||
console.log('Part 1: ' + day4.part1(fs.readFileSync('input.txt').toString()));
|
||||
console.log('Part 2: ' + day4.part2(fs.readFileSync('input.txt').toString()));
|
||||
1
AdventOfCode2018/5thDay/challenge1/input.txt
Normal file
1
AdventOfCode2018/5thDay/challenge1/input.txt
Normal file
File diff suppressed because one or more lines are too long
44
AdventOfCode2018/5thDay/challenge1/istolethisfromsomeone.js
Normal file
44
AdventOfCode2018/5thDay/challenge1/istolethisfromsomeone.js
Normal file
@@ -0,0 +1,44 @@
|
||||
function part1(data) {
|
||||
const polymer = data.split("");
|
||||
const removeChar = ""; // No removal
|
||||
const stack = collapsePloymer(polymer, removeChar);
|
||||
return stack.length;
|
||||
}
|
||||
|
||||
function collapsePloymer(ploymerChars, removeChar) {
|
||||
const stack = [];
|
||||
for (let i = 0; i < ploymerChars.length; i++) {
|
||||
const char = ploymerChars[i];
|
||||
if (char.toLowerCase() === removeChar.toLowerCase()) {
|
||||
continue;
|
||||
}
|
||||
const last = stack.pop();
|
||||
if (!last) {
|
||||
stack.push(char);
|
||||
continue;
|
||||
}
|
||||
if (last.toLowerCase() === char.toLowerCase() && last !== char) {
|
||||
continue;
|
||||
}
|
||||
stack.push(last);
|
||||
stack.push(char);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
function part2(data) {
|
||||
const polymer = data.split("");
|
||||
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
||||
const collapsedPolymers = alphabet.map(letter =>
|
||||
collapsePloymer(polymer, letter)
|
||||
);
|
||||
const shortestCollapse = collapsedPolymers.reduce((longest, curr) =>
|
||||
longest.length < curr.length ? longest : curr
|
||||
);
|
||||
return shortestCollapse.length;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
part1: part1,
|
||||
part2: part2
|
||||
};
|
||||
43
AdventOfCode2018/5thDay/challenge1/main.cpp
Normal file
43
AdventOfCode2018/5thDay/challenge1/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 2) return 0;
|
||||
|
||||
std::fstream input;
|
||||
input.open(*(argv + 1));
|
||||
|
||||
std::string polymerString;
|
||||
std::getline(input, polymerString);
|
||||
|
||||
while (!false) {
|
||||
int numOfMods = 0;
|
||||
std::string eh = "";
|
||||
for (unsigned int i = 0; i < polymerString.length() - 1; i++) {
|
||||
if (islower((char)polymerString[i])) {
|
||||
if (toupper((char)polymerString[i]) == (char)polymerString[i+1]) {
|
||||
eh += polymerString.substr(0, i);
|
||||
eh += polymerString.substr(i + 2, polymerString.length());
|
||||
numOfMods++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isupper((char)polymerString[i])) {
|
||||
if (tolower((char)polymerString[i]) == (char)polymerString[i+1]) {
|
||||
eh += polymerString.substr(0, i);
|
||||
eh += polymerString.substr(i + 2, polymerString.length());
|
||||
numOfMods++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (eh != "") {
|
||||
polymerString = eh;
|
||||
}
|
||||
std::cout << "Current length: " <<polymerString.length() << std::endl;
|
||||
if (numOfMods == 0) break;
|
||||
}
|
||||
std::cout << "Found polymers: " << polymerString << std::endl;
|
||||
std::cout << "At length: " << polymerString.length() << std::endl;
|
||||
}
|
||||
14
AdventOfCode2018/5thDay/challenge2/challenge.txt
Normal file
14
AdventOfCode2018/5thDay/challenge2/challenge.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
--- Part Two ---
|
||||
Time to improve the polymer.
|
||||
|
||||
One of the unit types is causing problems; it's preventing the polymer from collapsing as much as it should. Your goal is to figure out which unit type is causing the most problems, remove all instances of it (regardless of polarity), fully react the remaining polymer, and measure its length.
|
||||
|
||||
For example, again using the polymer dabAcCaCBAcCcaDA from above:
|
||||
|
||||
Removing all A/a units produces dbcCCBcCcD. Fully reacting this polymer produces dbCBcD, which has length 6.
|
||||
Removing all B/b units produces daAcCaCAcCcaDA. Fully reacting this polymer produces daCAcaDA, which has length 8.
|
||||
Removing all C/c units produces dabAaBAaDA. Fully reacting this polymer produces daDA, which has length 4.
|
||||
Removing all D/d units produces abAcCaCBAcCcaA. Fully reacting this polymer produces abCBAc, which has length 6.
|
||||
In this example, removing all C/c units was best, producing the answer 4.
|
||||
|
||||
What is the length of the shortest polymer you can produce by removing all units of exactly one type and fully reacting the result?
|
||||
1
AdventOfCode2018/5thDay/challenge2/input.txt
Normal file
1
AdventOfCode2018/5thDay/challenge2/input.txt
Normal file
File diff suppressed because one or more lines are too long
0
AdventOfCode2018/5thDay/challenge2/main.cpp
Normal file
0
AdventOfCode2018/5thDay/challenge2/main.cpp
Normal file
BIN
AdventOfCode2018/6thDay/a.out
Executable file
BIN
AdventOfCode2018/6thDay/a.out
Executable file
Binary file not shown.
81
AdventOfCode2018/6thDay/challenge.txt
Normal file
81
AdventOfCode2018/6thDay/challenge.txt
Normal file
@@ -0,0 +1,81 @@
|
||||
--- Day 6: Chronal Coordinates ---
|
||||
The device on your wrist beeps several times, and once again you feel like you're falling.
|
||||
|
||||
"Situation critical," the device announces. "Destination indeterminate. Chronal interference detected. Please specify new target coordinates."
|
||||
|
||||
The device then produces a list of coordinates (your puzzle input). Are they places it thinks are safe or dangerous? It recommends you check manual page 729. The Elves did not give you a manual.
|
||||
|
||||
If they're dangerous, maybe you can minimize the danger by finding the coordinate that gives the largest distance from the other points.
|
||||
|
||||
Using only the Manhattan distance, determine the area around each coordinate by counting the number of integer X,Y locations that are closest to that coordinate (and aren't tied in distance to any other coordinate).
|
||||
|
||||
Your goal is to find the size of the largest area that isn't infinite. For example, consider the following list of coordinates:
|
||||
|
||||
1, 1
|
||||
1, 6
|
||||
8, 3
|
||||
3, 4
|
||||
5, 5
|
||||
8, 9
|
||||
If we name these coordinates A through F, we can draw them on a grid, putting 0,0 at the top left:
|
||||
|
||||
..........
|
||||
.A........
|
||||
..........
|
||||
........C.
|
||||
...D......
|
||||
.....E....
|
||||
.B........
|
||||
..........
|
||||
..........
|
||||
........F.
|
||||
This view is partial - the actual grid extends infinitely in all directions. Using the Manhattan distance, each location's closest coordinate can be determined, shown here in lowercase:
|
||||
|
||||
aaaaa.cccc
|
||||
aAaaa.cccc
|
||||
aaaddecccc
|
||||
aadddeccCc
|
||||
..dDdeeccc
|
||||
bb.deEeecc
|
||||
bBb.eeee..
|
||||
bbb.eeefff
|
||||
bbb.eeffff
|
||||
bbb.ffffFf
|
||||
Locations shown as . are equally far from two or more coordinates, and so they don't count as being closest to any.
|
||||
|
||||
In this example, the areas of coordinates A, B, C, and F are infinite - while not shown here, their areas extend forever outside the visible grid. However, the areas of coordinates D and E are finite: D is closest to 9 locations, and E is closest to 17 (both including the coordinate's location itself). Therefore, in this example, the size of the largest area is 17.
|
||||
|
||||
What is the size of the largest area that isn't infinite?
|
||||
|
||||
--- Part Two ---
|
||||
On the other hand, if the coordinates are safe, maybe the best you can do is try to find a region near as many coordinates as possible.
|
||||
|
||||
For example, suppose you want the sum of the Manhattan distance to all of the coordinates to be less than 32. For each location, add up the distances to all of the given coordinates; if the total of those distances is less than 32, that location is within the desired region. Using the same coordinates as above, the resulting region looks like this:
|
||||
|
||||
..........
|
||||
.A........
|
||||
..........
|
||||
...###..C.
|
||||
..#D###...
|
||||
..###E#...
|
||||
.B.###....
|
||||
..........
|
||||
..........
|
||||
........F.
|
||||
In particular, consider the highlighted location 4,3 located at the top middle of the region. Its calculation is as follows, where abs() is the absolute value function:
|
||||
|
||||
Distance to coordinate A: abs(4-1) + abs(3-1) = 5
|
||||
Distance to coordinate B: abs(4-1) + abs(3-6) = 6
|
||||
Distance to coordinate C: abs(4-8) + abs(3-3) = 4
|
||||
Distance to coordinate D: abs(4-3) + abs(3-4) = 2
|
||||
Distance to coordinate E: abs(4-5) + abs(3-5) = 3
|
||||
Distance to coordinate F: abs(4-8) + abs(3-9) = 10
|
||||
Total distance: 5 + 6 + 4 + 2 + 3 + 10 = 30
|
||||
Because the total distance to all coordinates (30) is less than 32, the location is within the region.
|
||||
|
||||
This region, which also includes coordinates D and E, has a total size of 16.
|
||||
|
||||
Your actual region will need to be much larger than this example, though, instead including all locations with a total distance of less than 10000.
|
||||
|
||||
What is the size of the region containing all locations which have a total distance to all given coordinates of less than 10000?
|
||||
|
||||
50
AdventOfCode2018/6thDay/input.txt
Normal file
50
AdventOfCode2018/6thDay/input.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
194, 200
|
||||
299, 244
|
||||
269, 329
|
||||
292, 55
|
||||
211, 63
|
||||
123, 311
|
||||
212, 90
|
||||
292, 169
|
||||
359, 177
|
||||
354, 95
|
||||
101, 47
|
||||
95, 79
|
||||
95, 287
|
||||
294, 126
|
||||
81, 267
|
||||
330, 78
|
||||
202, 165
|
||||
225, 178
|
||||
266, 272
|
||||
351, 326
|
||||
180, 62
|
||||
102, 178
|
||||
151, 101
|
||||
343, 145
|
||||
205, 312
|
||||
74, 193
|
||||
221, 56
|
||||
89, 89
|
||||
242, 172
|
||||
59, 138
|
||||
83, 179
|
||||
223, 88
|
||||
297, 234
|
||||
147, 351
|
||||
226, 320
|
||||
358, 338
|
||||
321, 172
|
||||
54, 122
|
||||
263, 165
|
||||
126, 341
|
||||
64, 132
|
||||
264, 306
|
||||
72, 202
|
||||
98, 49
|
||||
238, 67
|
||||
310, 303
|
||||
277, 281
|
||||
222, 318
|
||||
357, 169
|
||||
123, 225
|
||||
131
AdventOfCode2018/6thDay/main.cpp
Normal file
131
AdventOfCode2018/6thDay/main.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
struct Point
|
||||
{
|
||||
int64_t x, y;
|
||||
Point(const int64_t &X, const int64_t &Y) : x(X), y(Y) {}
|
||||
Point() = default;
|
||||
};
|
||||
|
||||
int64_t distance(const Point &a, const Point &b)
|
||||
{
|
||||
return std::abs(a.x - b.x) + std::abs(a.y - b.y);
|
||||
}
|
||||
|
||||
std::istream &operator>>(std::istream &is, Point &p)
|
||||
{
|
||||
char c;
|
||||
is >> p.x >> c >> p.y;
|
||||
return is;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Point &p)
|
||||
{
|
||||
char c;
|
||||
os << p.x << ", " << p.y;
|
||||
return os;
|
||||
}
|
||||
|
||||
size_t min_index(const size_t &invalid, const Point &point,
|
||||
const std::vector<Point> &points)
|
||||
{
|
||||
size_t result;
|
||||
int64_t min_dist(std::numeric_limits<int64_t>::max());
|
||||
for(size_t p = 0; p < points.size(); ++p)
|
||||
{
|
||||
int64_t d(distance(point, points[p]));
|
||||
if(min_dist > d)
|
||||
{
|
||||
min_dist = d;
|
||||
result = p;
|
||||
}
|
||||
else if(min_dist == d)
|
||||
{
|
||||
result = invalid;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::ifstream infile(argv[1]);
|
||||
std::vector<Point> points(std::istream_iterator<Point>(infile), {});
|
||||
|
||||
int64_t min_x(std::numeric_limits<int64_t>::max()), min_y(min_x),
|
||||
max_x(std::numeric_limits<int64_t>::min()), max_y(max_x);
|
||||
for(auto &p : points)
|
||||
{
|
||||
min_x = std::min(min_x, p.x);
|
||||
min_y = std::min(min_y, p.y);
|
||||
max_x = std::max(max_x, p.x);
|
||||
max_y = std::max(max_y, p.y);
|
||||
}
|
||||
|
||||
int64_t width(max_x - min_x + 1), height(max_y - min_y + 1);
|
||||
const size_t invalid(points.size());
|
||||
std::vector<int64_t> num_claimed(points.size() + 1, 0);
|
||||
std::set<size_t> invalid_points;
|
||||
|
||||
for(int64_t x = min_x; x <= max_x; ++x)
|
||||
{
|
||||
invalid_points.insert(min_index(invalid, Point(x, min_y), points));
|
||||
invalid_points.insert(min_index(invalid, Point(x, max_y), points));
|
||||
}
|
||||
for(int64_t y = min_y; y <= max_y; ++y)
|
||||
{
|
||||
invalid_points.insert(min_index(invalid, Point(min_x, y), points));
|
||||
invalid_points.insert(min_index(invalid, Point(max_x, y), points));
|
||||
}
|
||||
|
||||
for(int64_t x = 0; x < width; ++x)
|
||||
for(int64_t y = 0; y < height; ++y)
|
||||
{
|
||||
int64_t min_dist(std::numeric_limits<int64_t>::max());
|
||||
size_t min_index;
|
||||
for(size_t p = 0; p < points.size(); ++p)
|
||||
{
|
||||
int64_t d(distance(Point(x + min_x, y + min_y), points[p]));
|
||||
if(min_dist > d)
|
||||
{
|
||||
min_dist = d;
|
||||
min_index = p;
|
||||
}
|
||||
else if(min_dist == d)
|
||||
{
|
||||
min_index = invalid;
|
||||
}
|
||||
}
|
||||
if(invalid_points.find(min_index) == invalid_points.end())
|
||||
++num_claimed[min_index];
|
||||
}
|
||||
std::cout << "Part 1: "
|
||||
<< *std::max_element(num_claimed.begin(), num_claimed.end())
|
||||
<< "\n";
|
||||
|
||||
int64_t area(0);
|
||||
constexpr int64_t cutoff(10000);
|
||||
const int64_t padding(cutoff / points.size() + 1);
|
||||
|
||||
const int64_t x_lower(min_x - padding), x_upper(max_x + 1 + padding),
|
||||
y_lower(min_y - padding), y_upper(max_y + 1 + padding);
|
||||
for(int64_t x = x_lower; x < x_upper; ++x)
|
||||
for(int64_t y = y_lower; y < y_upper; ++y)
|
||||
{
|
||||
int64_t total_dist(0);
|
||||
for(auto &point : points)
|
||||
{
|
||||
total_dist += distance(Point(x, y), point);
|
||||
if(total_dist > cutoff)
|
||||
break;
|
||||
}
|
||||
if(total_dist < cutoff)
|
||||
++area;
|
||||
}
|
||||
std::cout << "Part 2: " << area << "\n";
|
||||
}
|
||||
37
C++/brainfuckemulator/.vscode/settings.json
vendored
Normal file
37
C++/brainfuckemulator/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"fstream": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"tuple": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
||||
BIN
C++/brainfuckemulator/a.out
Executable file
BIN
C++/brainfuckemulator/a.out
Executable file
Binary file not shown.
2
C++/brainfuckemulator/fml.bf
Normal file
2
C++/brainfuckemulator/fml.bf
Normal file
@@ -0,0 +1,2 @@
|
||||
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>
|
||||
++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.
|
||||
87
C++/brainfuckemulator/main.cpp
Normal file
87
C++/brainfuckemulator/main.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
// > Increment the pointer.
|
||||
// < Decrement the pointer.
|
||||
// + Increment the byte at the pointer.
|
||||
// - Decrement the byte at the pointer.
|
||||
// . Output the byte at the pointer.
|
||||
// , Input a byte and store it in the byte at the pointer.
|
||||
// [ Jump forward past the matching ] if the byte at the pointer is zero.
|
||||
// ] Jump backward to the matching [ unless the byte at the pointer is zero.
|
||||
|
||||
class BrainFuck {
|
||||
public:
|
||||
char stack[30000];
|
||||
int programCounter = 0;
|
||||
char* ptr;
|
||||
std::string program;
|
||||
|
||||
BrainFuck(std::string program) {
|
||||
this->program = program;
|
||||
this->ptr = (char*)this->program.c_str();
|
||||
}
|
||||
|
||||
bool tick() {
|
||||
if (programCounter >= 30000) return false;
|
||||
int bal;
|
||||
switch((char)program[programCounter]) {
|
||||
case '>': ++ptr; break;
|
||||
case '<': --ptr; break;
|
||||
case '+': ++*ptr; break;
|
||||
case '-': --*ptr; break;
|
||||
case '.': programPrint(*ptr); break;
|
||||
case ',': break; // TODO GETS();
|
||||
case '[':
|
||||
bal = 1;
|
||||
if (*ptr == '\0') {
|
||||
do {
|
||||
programCounter++;
|
||||
if (program[programCounter] == '[') bal++;
|
||||
else if (program[programCounter] == ']') bal--;
|
||||
} while (bal != 0);
|
||||
}
|
||||
break;
|
||||
case ']':
|
||||
bal = 0;
|
||||
do {
|
||||
if (program[programCounter] == '[') bal++;
|
||||
else if (program[programCounter] == ']') bal--;
|
||||
programCounter--;
|
||||
} while (bal != 0);
|
||||
break;
|
||||
}
|
||||
programCounter++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void programPrint(char toPrint) {
|
||||
std::cout << "OUTPUT AT POSITION " << programCounter << ": ";
|
||||
putchar(toPrint);
|
||||
putchar('\n');
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {std::cout << "No input file specified" << std::endl; exit(0); }
|
||||
|
||||
std::ifstream input(*(argv + 1));
|
||||
std::string programStream;
|
||||
|
||||
for (std::string line; std::getline(input, line); )
|
||||
programStream += line;
|
||||
|
||||
programStream.erase(std::remove(programStream.begin(), programStream.end(), '\n'), programStream.end());
|
||||
|
||||
BrainFuck CPU(programStream);
|
||||
|
||||
while (1) {
|
||||
if (!CPU.tick()) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << programStream << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user