Added older advents

This commit is contained in:
Jos van Goor 2022-12-01 13:46:47 +01:00
parent 8db2505049
commit 9cf858b860
78 changed files with 13807 additions and 0 deletions

994
advent_of_code_2018/day1/input.in Executable file
View file

@ -0,0 +1,994 @@
+5
-11
-1
-16
+12
+9
-15
+20
+4
+17
-4
-14
+6
-17
+6
-19
-12
+17
-6
-18
+1
+15
-14
+10
-4
-2
+5
+6
+8
+3
+17
-9
+18
-1
+17
-15
+7
-6
-17
-17
+19
+19
-13
+18
-15
+16
+7
-10
-5
+22
+8
-13
+4
+3
+19
+17
-19
-1
-11
+2
+1
-13
+1
+3
-14
+16
-9
+19
+13
-20
+6
+22
+10
+6
+15
-13
-13
-8
+16
+20
-5
+1
+7
+11
-13
+5
-16
-2
-4
+25
-5
-10
-12
-9
+16
-2
-19
-3
-12
+5
+17
+16
+11
+16
+10
+4
+3
+11
-12
+19
+3
+17
+15
-6
-6
-4
+3
+10
+8
+15
-7
+13
+3
+6
+2
+16
+20
+3
-11
+3
-11
+12
+6
+3
+11
+5
+2
+12
-4
-2
+4
+3
-4
+20
+1
+19
+14
+5
-16
-15
-16
-4
-10
-13
-10
-18
+10
-6
-7
-3
-2
-14
+12
-2
-6
-11
-5
-6
+20
-11
-1
+9
-1
+5
+6
+11
-19
-9
-14
-4
-6
-1
+2
-6
-12
+20
-12
-13
-9
-3
-7
-17
+14
-9
+20
-4
-8
-1
-6
+16
+6
-18
-12
+6
-22
-15
+10
+6
+20
-16
+1
-18
+4
+19
+9
-17
+1
+13
+21
+23
-4
+7
-16
+3
-4
-3
-17
-20
-10
-20
+16
+3
+14
-11
+3
-29
-1
+7
-18
+5
-7
-16
+6
-7
-15
+9
+22
-2
-21
-18
+1
+10
+13
+13
-24
-6
-22
-10
+9
+4
-8
-16
+3
-5
-19
-6
-11
+3
-8
-16
-14
-16
-15
-6
+3
+13
+8
-19
-18
-8
+9
-15
-14
-2
+18
-17
+2
+18
-6
-3
-19
+16
-4
+6
+21
-6
+7
+17
-8
-4
+6
+19
-2
+5
+20
-3
-6
+5
+5
-17
-18
+16
+4
+7
+6
+8
+6
-1
+10
-13
-4
-10
+8
-14
+17
+9
+2
-7
-22
-16
+20
-13
+8
-17
+1
+19
+14
+19
+11
-6
+25
+18
+19
+5
+20
+17
+4
-10
+47
+4
-1
+23
+24
-8
-10
+31
+19
-11
-17
+8
-24
+9
+32
+18
-1
+4
-13
+4
+17
-2
+11
+11
+4
-3
-3
+22
+19
+14
-21
+13
+9
-14
-16
+20
+16
-14
+5
-15
+12
-11
+1
+3
-24
-9
-9
-22
-12
-10
-7
-3
+12
+13
+17
-11
+35
+12
-9
+16
+22
-18
-18
+19
-8
+23
+19
+3
+8
+15
-2
+11
+14
+10
+15
+8
-1
+13
+1
+18
-11
+4
+4
+11
+9
-18
-9
+13
-18
+10
+3
-6
-5
-10
-11
-14
-2
-9
+3
-4
-6
+13
-2
-17
-4
+7
+6
-12
-7
+14
-6
-18
+19
-18
-2
-13
+6
-15
+14
+7
+9
-14
+9
-19
+1
+13
-2
-10
-11
+13
-6
-6
+19
+10
+17
-8
-7
+19
+16
-1
+7
+16
-15
-17
+12
+16
-2
+14
-3
-16
-17
-5
+16
+29
-3
-2
+13
-18
+15
-4
-14
-12
-16
-19
+39
-9
+19
+3
-11
+10
+12
+19
-4
+12
+13
+19
+3
-19
+9
-16
+10
+18
+12
-6
-2
-11
+20
+15
+15
+4
+12
-38
+9
+33
+24
+6
+4
-36
-47
-15
-13
-3
+1
+12
+14
+9
-32
+7
-16
-5
-29
+12
-2
+15
-12
-11
-39
-40
+3
-34
-5
+78
+4
+52
+1
+90
+112
+152
-80
+81800
-18
+15
-9
+11
+2
-5
+16
-5
+15
-1
+2
-14
-7
+12
-10
-9
+20
+14
-9
+12
+9
+13
+3
+11
+14
-3
+10
+8
+12
+5
+10
+1
+14
-5
+1
-4
-13
+9
+18
+17
+16
+9
-1
-10
+13
+13
+11
-18
+15
-9
-13
+3
+1
+11
-3
-10
+19
-11
+13
+12
-8
-10
-6
+13
+5
-13
-7
-1
+18
+7
+14
-2
+5
+1
+16
-7
+18
+13
-6
+18
-1
+12
-4
-10
+7
-15
-9
-7
-7
-6
+11
-16
+7
-4
+11
-4
-6
-14
+1
+6
-3
+2
+21
+12
-16
+18
-5
+17
+4
+19
+6
-13
+17
-3
-2
-17
+7
-3
-7
+14
+17
+8
+7
-17
+18
-15
-4
+7
+2
+1
-14
-1
-6
+9
-10
-4
+15
-14
-18
-14
-9
-11
+9
+3
+12
+1
+3
-10
-15
+7
+6
+13
+9
+7
-4
+9
-14
+21
-9
+24
+10
+6
+6
-19
+22
-10
-18
+10
+14
-4
+3
+7
+14
+11
+16
-10
+11
-9
-5
-6
-2
-15
+3
-16
+19
+8
+2
-17
+3
+5
+14
-16
-4
-5
+1
-3
+4
+6
+18
+16
+4
-18
+6
+10
-6
+1
+6
+9
+17
-8
-15
-12
+1
-6
+4
+12
+2
+17
-9
-7
+10
+12
+17
+8
+15
+7
-18
-1
+4
+13
-3
+16
+4
+2
-8
-5
+14
+10
+18
-15
+19
-11
-4
-16
+13
+16
-15
+10
-20
-7
-15
-10
-2
-6
+19
-3
-9
-18
+12
-8
+3
+13
+20
+18
-16
+15
+12
+1
-18
+10
-14
-17
-7
-9
-20
+8
-9
+7
-11
-19
+7
-14
+6
+4
+14
+8
-11
+2
-1
-19
+16
+9
-10
+20
+12
+11
+13
-3
-2
+3
-20
+6
-17
+3
-9
-6
-16
+7
+7
-23
-6
+14
-3
-31
-18
-19
-12
-26
+23
+9
-7
-10
+22
+17
+17
-7
-8
+9
+28
+5
+24
-28
+36
+37
+7
+12
+19
+15
-3
-20
+17
+18
+4
-8
+9
-4
-2
-19
+11
-1
+3
-7
+8
+9
-8
+19
+9
+12
-11
-5
-13
+9
-6
+7
+17
-13
+16
+10
-5
+20
+6
-1
+17
-14
+10
+18
-1
+3
-10
-4
-10
-10
-16
-2
+7
+16
-12
+6
+8
+22
+7
-6
-13
-14
+10
-1
-21
-1
+8
-15
+9
-17
-2
-21
+4
-19
-13
-8
+26
+4
-27
-8
+2
+30
-11
-82484

View file

@ -0,0 +1,46 @@
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int read()
{
string line;
getline(cin, line);
bool plus = line[0] == '+';
int val = stoi(line.substr(1));
return plus ? val : -val;
}
int main()
{
vector<int> sequence;
while (!cin.eof())
sequence.push_back(read());
// cout << "Buffered " << sequence.size() << " frequencies\n";
int total = 0;
set<int> used;
used.insert(0);
while (true)
{
for (int i : sequence)
{
total += i;
if (used.find(total) != used.end())
{
cout << "Found first repeating frequency: " << total << "\n";
return 0;
}
used.insert(total);
}
}
}

View file

@ -0,0 +1,385 @@
position=<-52592, 31869> velocity=< 5, -3>
position=<-20934, 52988> velocity=< 2, -5>
position=<-20910, 31871> velocity=< 2, -3>
position=<-31503, -52596> velocity=< 3, 5>
position=<-42061, -10364> velocity=< 4, 1>
position=< 10776, -31475> velocity=<-1, 3>
position=<-10348, 31875> velocity=< 1, -3>
position=< 52969, 52985> velocity=<-5, -5>
position=< 31848, -10366> velocity=<-3, 1>
position=<-10376, -10366> velocity=< 1, 1>
position=<-10376, -31474> velocity=< 1, 3>
position=<-42058, 52990> velocity=< 4, -5>
position=<-52628, -10358> velocity=< 5, 1>
position=<-52630, 52985> velocity=< 5, -5>
position=< 31888, -31474> velocity=<-3, 3>
position=<-31492, 42429> velocity=< 3, -4>
position=< 31892, 52988> velocity=<-3, -5>
position=< 52961, 52989> velocity=<-5, -5>
position=<-20908, -42031> velocity=< 2, 4>
position=<-52627, 10759> velocity=< 5, -1>
position=< 21307, -42034> velocity=<-2, 4>
position=<-20937, -31475> velocity=< 2, 3>
position=< 21315, -52594> velocity=<-2, 5>
position=< 10744, -10366> velocity=<-1, 1>
position=< 21287, -10358> velocity=<-2, 1>
position=< 21298, -31478> velocity=<-2, 3>
position=<-10384, 31866> velocity=< 1, -3>
position=< 52953, -10364> velocity=<-5, 1>
position=<-42029, -52597> velocity=< 4, 5>
position=< 21319, 10757> velocity=<-2, -1>
position=<-10352, 21310> velocity=< 1, -2>
position=<-10395, -42034> velocity=< 1, 4>
position=< 10756, 31873> velocity=<-1, -3>
position=<-10384, 42425> velocity=< 1, -4>
position=<-42050, 42427> velocity=< 4, -4>
position=< 31866, 10759> velocity=<-3, -1>
position=<-52592, -10357> velocity=< 5, 1>
position=<-42066, 31874> velocity=< 4, -3>
position=<-52605, -20924> velocity=< 5, 2>
position=< 21274, 10753> velocity=<-2, -1>
position=<-20933, 42433> velocity=< 2, -4>
position=< 52961, -10365> velocity=<-5, 1>
position=<-20913, -20923> velocity=< 2, 2>
position=< 10716, -42039> velocity=<-1, 4>
position=<-42070, 21315> velocity=< 4, -2>
position=<-42040, 31875> velocity=< 4, -3>
position=<-42029, 52989> velocity=< 4, -5>
position=< 52953, -20917> velocity=<-5, 2>
position=<-42058, -10364> velocity=< 4, 1>
position=<-52574, -42031> velocity=< 5, 4>
position=<-52600, -42032> velocity=< 5, 4>
position=< 10740, -52598> velocity=<-1, 5>
position=< 42438, -20919> velocity=<-4, 2>
position=<-20937, -31477> velocity=< 2, 3>
position=<-42072, 42427> velocity=< 4, -4>
position=<-20921, -52598> velocity=< 2, 5>
position=<-52619, -20918> velocity=< 5, 2>
position=<-31467, -20915> velocity=< 3, 2>
position=<-42066, -10366> velocity=< 4, 1>
position=< 21334, -42035> velocity=<-2, 4>
position=< 21309, 21317> velocity=<-2, -2>
position=< 42414, -10364> velocity=<-4, 1>
position=< 21290, 21311> velocity=<-2, -2>
position=< 52972, -20917> velocity=<-5, 2>
position=< 10776, 10755> velocity=<-1, -1>
position=< 21298, -10363> velocity=<-2, 1>
position=< 42430, 52986> velocity=<-4, -5>
position=< 21294, 21312> velocity=<-2, -2>
position=< 10752, -10357> velocity=<-1, 1>
position=< 42438, 21315> velocity=<-4, -2>
position=<-42050, -20915> velocity=< 4, 2>
position=<-31504, -52598> velocity=< 3, 5>
position=< 52999, 21317> velocity=<-5, -2>
position=<-10390, -10362> velocity=< 1, 1>
position=< 21300, 10754> velocity=<-2, -1>
position=<-20933, -10366> velocity=< 2, 1>
position=< 10725, -10366> velocity=<-1, 1>
position=< 10737, 31874> velocity=<-1, -3>
position=<-20913, 10758> velocity=< 2, -1>
position=<-42063, 21312> velocity=< 4, -2>
position=<-10358, 10754> velocity=< 1, -1>
position=< 21334, 52986> velocity=<-2, -5>
position=< 42430, 31871> velocity=<-4, -3>
position=< 21319, 21310> velocity=<-2, -2>
position=< 21290, -52592> velocity=<-2, 5>
position=< 21295, 10753> velocity=<-2, -1>
position=< 42390, -42036> velocity=<-4, 4>
position=< 10721, 52990> velocity=<-1, -5>
position=< 21285, -52598> velocity=<-2, 5>
position=< 31837, -42037> velocity=<-3, 4>
position=<-42018, 52989> velocity=< 4, -5>
position=<-10355, 31871> velocity=< 1, -3>
position=< 42411, -31477> velocity=<-4, 3>
position=<-52632, 42428> velocity=< 5, -4>
position=< 42441, 10759> velocity=<-4, -1>
position=<-52624, -10365> velocity=< 5, 1>
position=<-10360, -42038> velocity=< 1, 4>
position=< 21314, 21311> velocity=<-2, -2>
position=< 52988, 42430> velocity=<-5, -4>
position=<-10350, -31482> velocity=< 1, 3>
position=<-52592, 10753> velocity=< 5, -1>
position=<-20954, -52590> velocity=< 2, 5>
position=<-52611, -42033> velocity=< 5, 4>
position=< 31841, 42424> velocity=<-3, -4>
position=< 10729, 52990> velocity=<-1, -5>
position=< 31837, 42426> velocity=<-3, -4>
position=<-20958, 42429> velocity=< 2, -4>
position=< 10737, 42432> velocity=<-1, -4>
position=<-52624, -31477> velocity=< 5, 3>
position=<-20949, 10754> velocity=< 2, -1>
position=< 10729, -20923> velocity=<-1, 2>
position=< 31892, -52597> velocity=<-3, 5>
position=<-10355, 21314> velocity=< 1, -2>
position=< 52960, 42428> velocity=<-5, -4>
position=<-52587, 42424> velocity=< 5, -4>
position=<-52592, 52983> velocity=< 5, -5>
position=< 31832, 21315> velocity=<-3, -2>
position=< 52956, -10362> velocity=<-5, 1>
position=< 52992, 42428> velocity=<-5, -4>
position=< 10749, -20924> velocity=<-1, 2>
position=<-31504, 21308> velocity=< 3, -2>
position=<-20950, -42032> velocity=< 2, 4>
position=<-20907, 31866> velocity=< 2, -3>
position=<-52624, 42432> velocity=< 5, -4>
position=< 31865, -10357> velocity=<-3, 1>
position=<-52611, 52988> velocity=< 5, -5>
position=< 42441, 31866> velocity=<-4, -3>
position=< 42438, 21309> velocity=<-4, -2>
position=< 42398, 21310> velocity=<-4, -2>
position=<-10352, -10360> velocity=< 1, 1>
position=<-42050, -42036> velocity=< 4, 4>
position=< 52948, 42429> velocity=<-5, -4>
position=< 52993, 21311> velocity=<-5, -2>
position=<-10384, -52598> velocity=< 1, 5>
position=<-42029, -31473> velocity=< 4, 3>
position=<-10375, -52589> velocity=< 1, 5>
position=<-31460, -31475> velocity=< 3, 3>
position=< 42418, -31473> velocity=<-4, 3>
position=<-10392, 52984> velocity=< 1, -5>
position=< 10767, 10750> velocity=<-1, -1>
position=<-52573, 52991> velocity=< 5, -5>
position=<-52611, 52984> velocity=< 5, -5>
position=<-52592, 42431> velocity=< 5, -4>
position=<-10380, 21312> velocity=< 1, -2>
position=<-42029, -42038> velocity=< 4, 4>
position=<-42056, -10362> velocity=< 4, 1>
position=<-42041, -20915> velocity=< 4, 2>
position=<-10395, 31868> velocity=< 1, -3>
position=<-42045, 52991> velocity=< 4, -5>
position=< 21319, 21313> velocity=<-2, -2>
position=< 31844, -20920> velocity=<-3, 2>
position=<-20918, 52990> velocity=< 2, -5>
position=<-31514, -52595> velocity=< 3, 5>
position=< 10752, 31869> velocity=<-1, -3>
position=<-42034, -52597> velocity=< 4, 5>
position=< 10733, -20920> velocity=<-1, 2>
position=<-31476, 21309> velocity=< 3, -2>
position=< 10716, -42037> velocity=<-1, 4>
position=< 10720, 42431> velocity=<-1, -4>
position=<-20909, -20915> velocity=< 2, 2>
position=<-52627, 10750> velocity=< 5, -1>
position=<-31489, -52589> velocity=< 3, 5>
position=< 10756, -20915> velocity=<-1, 2>
position=<-31483, -20918> velocity=< 3, 2>
position=< 31861, 10759> velocity=<-3, -1>
position=<-31471, 21308> velocity=< 3, -2>
position=< 52948, -42040> velocity=<-5, 4>
position=< 21302, -31478> velocity=<-2, 3>
position=<-52587, -31476> velocity=< 5, 3>
position=< 21308, -31477> velocity=<-2, 3>
position=<-31492, 42429> velocity=< 3, -4>
position=<-31513, -31476> velocity=< 3, 3>
position=<-10388, -52598> velocity=< 1, 5>
position=<-20953, 31867> velocity=< 2, -3>
position=<-42038, -20921> velocity=< 4, 2>
position=< 10732, 31870> velocity=<-1, -3>
position=< 52964, -52595> velocity=<-5, 5>
position=< 21284, 10750> velocity=<-2, -1>
position=< 21299, 21317> velocity=<-2, -2>
position=<-42041, 31872> velocity=< 4, -3>
position=<-10360, 10750> velocity=< 1, -1>
position=< 10774, 10759> velocity=<-1, -1>
position=< 42406, 42429> velocity=<-4, -4>
position=<-42022, 42433> velocity=< 4, -4>
position=<-52606, 42428> velocity=< 5, -4>
position=< 31832, -31476> velocity=<-3, 3>
position=< 21295, -20923> velocity=<-2, 2>
position=<-42050, -42039> velocity=< 4, 4>
position=< 21284, -52594> velocity=<-2, 5>
position=<-42034, -42035> velocity=< 4, 4>
position=< 21279, 21313> velocity=<-2, -2>
position=< 31880, 42427> velocity=<-3, -4>
position=<-31484, 21317> velocity=< 3, -2>
position=< 42391, -20922> velocity=<-4, 2>
position=<-42058, -10365> velocity=< 4, 1>
position=< 42409, 52986> velocity=<-4, -5>
position=<-20918, 42431> velocity=< 2, -4>
position=< 31851, 21312> velocity=<-3, -2>
position=<-10387, -31479> velocity=< 1, 3>
position=<-42033, -31478> velocity=< 4, 3>
position=<-42047, -42036> velocity=< 4, 4>
position=< 21301, -31482> velocity=<-2, 3>
position=<-10365, -31473> velocity=< 1, 3>
position=<-31471, -42031> velocity=< 3, 4>
position=<-42074, -10357> velocity=< 4, 1>
position=<-31500, 10758> velocity=< 3, -1>
position=< 21311, 10751> velocity=<-2, -1>
position=< 42398, -10362> velocity=<-4, 1>
position=<-20921, 42424> velocity=< 2, -4>
position=< 52985, -52597> velocity=<-5, 5>
position=<-42073, 52983> velocity=< 4, -5>
position=< 42390, 31874> velocity=<-4, -3>
position=<-42061, -10360> velocity=< 4, 1>
position=< 21301, 42428> velocity=<-2, -4>
position=<-20942, -20917> velocity=< 2, 2>
position=<-10350, -52589> velocity=< 1, 5>
position=<-52595, 31875> velocity=< 5, -3>
position=< 42432, -52594> velocity=<-4, 5>
position=<-20937, -20924> velocity=< 2, 2>
position=< 42395, 31873> velocity=<-4, -3>
position=<-31508, 42433> velocity=< 3, -4>
position=< 10751, -31473> velocity=<-1, 3>
position=<-42032, 52986> velocity=< 4, -5>
position=< 42447, -10357> velocity=<-4, 1>
position=<-42048, 42428> velocity=< 4, -4>
position=<-10344, -42032> velocity=< 1, 4>
position=< 21290, -42034> velocity=<-2, 4>
position=<-42014, -42037> velocity=< 4, 4>
position=<-20906, -42040> velocity=< 2, 4>
position=< 10721, -20920> velocity=<-1, 2>
position=<-10379, 42433> velocity=< 1, -4>
position=< 21319, 52986> velocity=<-2, -5>
position=<-10368, 42431> velocity=< 1, -4>
position=<-20950, -20924> velocity=< 2, 2>
position=< 31877, -52595> velocity=<-3, 5>
position=<-31482, 42429> velocity=< 3, -4>
position=< 21334, 42432> velocity=<-2, -4>
position=<-10364, 42427> velocity=< 1, -4>
position=<-42074, 10755> velocity=< 4, -1>
position=< 21300, -10366> velocity=<-2, 1>
position=< 42408, 10754> velocity=<-4, -1>
position=< 10732, 10753> velocity=<-1, -1>
position=<-52632, 21310> velocity=< 5, -2>
position=< 10740, -20920> velocity=<-1, 2>
position=< 52956, 42429> velocity=<-5, -4>
position=< 10756, -52598> velocity=<-1, 5>
position=<-31506, 52991> velocity=< 3, -5>
position=< 10724, 10751> velocity=<-1, -1>
position=<-20921, 21310> velocity=< 2, -2>
position=<-20946, -42031> velocity=< 2, 4>
position=< 42435, 52986> velocity=<-4, -5>
position=<-42037, -31473> velocity=< 4, 3>
position=< 21287, -52592> velocity=<-2, 5>
position=< 10717, -42039> velocity=<-1, 4>
position=<-52627, 31872> velocity=< 5, -3>
position=< 31875, 52986> velocity=<-3, -5>
position=< 42411, -42036> velocity=<-4, 4>
position=< 52964, -20915> velocity=<-5, 2>
position=<-31488, 42428> velocity=< 3, -4>
position=< 42426, 21308> velocity=<-4, -2>
position=<-52579, 10751> velocity=< 5, -1>
position=<-42014, 10753> velocity=< 4, -1>
position=<-42034, 10752> velocity=< 4, -1>
position=< 21275, 42425> velocity=<-2, -4>
position=<-10350, -10366> velocity=< 1, 1>
position=<-52628, -52591> velocity=< 5, 5>
position=< 31845, -52591> velocity=<-3, 5>
position=< 21285, -31473> velocity=<-2, 3>
position=< 21319, 21312> velocity=<-2, -2>
position=< 42427, -31480> velocity=<-4, 3>
position=< 52956, -52591> velocity=<-5, 5>
position=<-10389, 52986> velocity=< 1, -5>
position=< 42400, 10754> velocity=<-4, -1>
position=<-31508, -10362> velocity=< 3, 1>
position=< 10740, 10756> velocity=<-1, -1>
position=<-20898, 42424> velocity=< 2, -4>
position=< 21319, -42031> velocity=<-2, 4>
position=<-52574, 10759> velocity=< 5, -1>
position=< 21274, -31476> velocity=<-2, 3>
position=<-31463, -10358> velocity=< 3, 1>
position=<-20950, 21311> velocity=< 2, -2>
position=<-52600, -31474> velocity=< 5, 3>
position=< 31864, 42431> velocity=<-3, -4>
position=< 21279, 21316> velocity=<-2, -2>
position=< 21287, 42426> velocity=<-2, -4>
position=< 10716, 10754> velocity=<-1, -1>
position=<-42042, 52989> velocity=< 4, -5>
position=<-31492, 42427> velocity=< 3, -4>
position=< 21298, -10364> velocity=<-2, 1>
position=<-42040, 21308> velocity=< 4, -2>
position=<-42045, 10750> velocity=< 4, -1>
position=< 31835, -20919> velocity=<-3, 2>
position=< 10773, 42433> velocity=<-1, -4>
position=< 42443, 10758> velocity=<-4, -1>
position=< 52973, -52598> velocity=<-5, 5>
position=< 21295, -52592> velocity=<-2, 5>
position=<-10392, 31868> velocity=< 1, -3>
position=< 21282, -42031> velocity=<-2, 4>
position=< 10737, -20920> velocity=<-1, 2>
position=< 52985, 31875> velocity=<-5, -3>
position=<-42049, -20920> velocity=< 4, 2>
position=< 52992, 10754> velocity=<-5, -1>
position=< 10716, 31866> velocity=<-1, -3>
position=< 31884, -20924> velocity=<-3, 2>
position=< 42442, -20924> velocity=<-4, 2>
position=< 10732, -10361> velocity=<-1, 1>
position=<-31508, 10756> velocity=< 3, -1>
position=< 31872, 21314> velocity=<-3, -2>
position=<-42042, 10750> velocity=< 4, -1>
position=<-42069, 21315> velocity=< 4, -2>
position=<-20898, -10365> velocity=< 2, 1>
position=<-42071, -20918> velocity=< 4, 2>
position=< 10752, -10357> velocity=<-1, 1>
position=<-20946, -10362> velocity=< 2, 1>
position=<-52572, -10358> velocity=< 5, 1>
position=< 10716, 42424> velocity=<-1, -4>
position=<-52611, 42426> velocity=< 5, -4>
position=< 31856, 52991> velocity=<-3, -5>
position=< 10750, 52982> velocity=<-1, -5>
position=<-31495, -52598> velocity=< 3, 5>
position=< 52975, 21308> velocity=<-5, -2>
position=< 10729, -20919> velocity=<-1, 2>
position=<-52620, 10759> velocity=< 5, -1>
position=< 10751, -10366> velocity=<-1, 1>
position=<-20898, -52591> velocity=< 2, 5>
position=<-42023, 52991> velocity=< 4, -5>
position=<-31500, 31875> velocity=< 3, -3>
position=<-52584, 52990> velocity=< 5, -5>
position=< 21314, 52990> velocity=<-2, -5>
position=< 10776, 21309> velocity=<-1, -2>
position=<-10376, 31875> velocity=< 1, -3>
position=<-20946, -52589> velocity=< 2, 5>
position=<-52628, -52590> velocity=< 5, 5>
position=< 52988, -31474> velocity=<-5, 3>
position=<-31491, -42040> velocity=< 3, 4>
position=<-20918, -42036> velocity=< 2, 4>
position=<-20947, 10754> velocity=< 2, -1>
position=< 52953, -31474> velocity=<-5, 3>
position=<-42031, 31870> velocity=< 4, -3>
position=<-52583, 42424> velocity=< 5, -4>
position=< 42393, -20919> velocity=<-4, 2>
position=< 42411, 10750> velocity=<-4, -1>
position=< 10716, -42032> velocity=<-1, 4>
position=<-31503, 42429> velocity=< 3, -4>
position=<-42053, 10753> velocity=< 4, -1>
position=<-31481, -20920> velocity=< 3, 2>
position=<-31468, -31481> velocity=< 3, 3>
position=< 21284, -20924> velocity=<-2, 2>
position=< 42409, -42036> velocity=<-4, 4>
position=<-42063, 31875> velocity=< 4, -3>
position=< 42450, -10358> velocity=<-4, 1>
position=<-20897, -52598> velocity=< 2, 5>
position=< 42407, -10362> velocity=<-4, 1>
position=< 52983, 10754> velocity=<-5, -1>
position=< 52969, -31477> velocity=<-5, 3>
position=< 53000, -10357> velocity=<-5, 1>
position=<-52619, -31475> velocity=< 5, 3>
position=< 10756, 10756> velocity=<-1, -1>
position=< 31889, -42031> velocity=<-3, 4>
position=<-31511, 52985> velocity=< 3, -5>
position=<-31511, 42425> velocity=< 3, -4>
position=< 21322, -31476> velocity=<-2, 3>
position=< 10764, 21312> velocity=<-1, -2>
position=< 10724, 21314> velocity=<-1, -2>
position=< 53001, 10758> velocity=<-5, -1>
position=<-52607, -10362> velocity=< 5, 1>
position=<-31482, -20919> velocity=< 3, 2>
position=< 21276, 10754> velocity=<-2, -1>
position=< 42426, 21317> velocity=<-4, -2>
position=< 21299, -10362> velocity=<-2, 1>
position=< 42450, -20922> velocity=<-4, 2>
position=< 10719, 10755> velocity=<-1, -1>
position=<-52623, 10759> velocity=< 5, -1>
position=< 31840, -42040> velocity=<-3, 4>
position=< 10724, -20918> velocity=<-1, 2>
position=<-10341, 21308> velocity=< 1, -2>
position=< 42403, -10365> velocity=<-4, 1>
position=< 31877, 31866> velocity=<-3, -3>
position=<-42048, 31875> velocity=< 4, -3>
position=< 52953, 52986> velocity=<-5, -5>
position=<-10340, -10360> velocity=< 1, 1>
position=< 31869, 10752> velocity=<-3, -1>
position=<-52612, 21312> velocity=< 5, -2>
position=<-42053, -52592> velocity=< 4, 5>
position=<-31490, 10750> velocity=< 3, -1>

View file

@ -0,0 +1,49 @@
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Position
{
int xpos;
int ypos;
Position() : xpos(0), ypos(0) {}
};
struct Velocity
{
int dx;
int dy;
Velocity() : dx(0), dy(0) {}
};
inline istream &operator>>(istream &in, Position &position)
{
cin.ignore(10); //ignore 'position=<'
cin >> position.xpos;
cin.ignore(2); //ignore ', '
cin >> position.ypos;
cin.ignore(2); //ignore '> '
return in;
}
inline istream &operator>>(istream &in, Velocity &velocity)
{
cin.ignore(10); //ignore 'velocity=<'
cin >> velocity.dx;
cin.ignore(2); //ignore ', '
cin >> velocity.dy;
cin.ignore(2); // ignore '>\n'
return in;
}
inline Position operator+(Position pos, Velocity const &vel)
{
pos.xpos += vel.dx;
pos.ypos += vel.dy;
return pos;
}

View file

@ -0,0 +1,101 @@
#include "main.ih"
struct Star
{
Position pos;
Velocity vel;
void update()
{
pos = pos + vel;
}
};
Star read_star()
{
Star rval;
cin >> rval.pos;
cin >> rval.vel;
return rval;
}
size_t grid_size(vector<Star> const &stars)
{
int minx = numeric_limits<int>::max();
int maxx = numeric_limits<int>::min();
int miny = minx;
int maxy = maxx;
for (Star const &star : stars)
{
minx = min(minx, star.pos.xpos);
maxx = max(maxx, star.pos.xpos);
miny = min(miny, star.pos.ypos);
maxy = max(maxy, star.pos.ypos);
}
size_t width = maxx - minx + 1;
size_t height = maxy - miny + 1;
return width * height;
}
void write_to_console(vector<Star> const &stars)
{
int minx = numeric_limits<int>::max();
int maxx = numeric_limits<int>::min();
int miny = minx;
int maxy = maxx;
for (Star const &star : stars)
{
minx = min(minx, star.pos.xpos);
maxx = max(maxx, star.pos.xpos);
miny = min(miny, star.pos.ypos);
maxy = max(maxy, star.pos.ypos);
}
int xpos = minx;
int ypos = miny;
int width = maxx - minx + 1;
int height = maxy - miny + 1;
vector<vector<bool>> grid;
grid.resize(width, vector<bool>(height));
for (Star const &star : stars)
grid[star.pos.xpos - xpos][star.pos.ypos - ypos] = true;
for (int idy = 0; idy < height; ++idy)
{
for (int idx = 0; idx < width; ++idx)
cout << (grid[idx][idy] ? '#' : ' ');
cout << "\n";
}
}
int main()
{
vector<Star> stars;
while (!cin.eof())
stars.push_back(read_star());
size_t size = grid_size(stars);
for (size_t time = 0; true; ++time)
{
vector<Star> next_position(stars);
for (Star &star : next_position)
star.update();
size_t next_size = grid_size(next_position);
if (next_size > size)
{
write_to_console(stars);
cout << "That took " << time << " seconds!\n"; // part 2
return 0;
}
stars.swap(next_position);
size = next_size;
}
}

View file

@ -0,0 +1,31 @@
position=< 9, 1> velocity=< 0, 2>
position=< 7, 0> velocity=<-1, 0>
position=< 3, -2> velocity=<-1, 1>
position=< 6, 10> velocity=<-2, -1>
position=< 2, -4> velocity=< 2, 2>
position=<-6, 10> velocity=< 2, -2>
position=< 1, 8> velocity=< 1, -1>
position=< 1, 7> velocity=< 1, 0>
position=<-3, 11> velocity=< 1, -2>
position=< 7, 6> velocity=<-1, -1>
position=<-2, 3> velocity=< 1, 0>
position=<-4, 3> velocity=< 2, 0>
position=<10, -3> velocity=<-1, 1>
position=< 5, 11> velocity=< 1, -2>
position=< 4, 7> velocity=< 0, -1>
position=< 8, -2> velocity=< 0, 1>
position=<15, 0> velocity=<-2, 0>
position=< 1, 6> velocity=< 1, 0>
position=< 8, 9> velocity=< 0, -1>
position=< 3, 3> velocity=<-1, 1>
position=< 0, 5> velocity=< 0, -1>
position=<-2, 2> velocity=< 2, 0>
position=< 5, -2> velocity=< 1, 2>
position=< 1, 4> velocity=< 2, 1>
position=<-2, 7> velocity=< 2, -2>
position=< 3, 6> velocity=<-1, -1>
position=< 5, 0> velocity=< 1, 0>
position=<-6, 0> velocity=< 2, 0>
position=< 5, 9> velocity=< 1, -2>
position=<14, 7> velocity=<-2, 0>
position=<-3, 6> velocity=< 2, -1>

View file

@ -0,0 +1,3 @@
8199
300
300

View file

@ -0,0 +1,80 @@
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int evaluate_square(vector<vector<int>> const &grid, size_t topx, size_t lefty, size_t size = 3)
{
int sum = 0;
for (size_t idx = 0; idx != size; ++idx)
{
for (size_t idy = 0; idy != size; ++idy)
sum += grid[topx + idx][lefty + idy];
}
return sum;
}
int main()
{
size_t grid_width;
size_t grid_height;
int grid_serial_number;
cin >> grid_serial_number;
cin >> grid_width;
cin >> grid_height;
vector<vector<int>> grid;
grid.resize(grid_width, vector<int>(grid_height, 0));
for (size_t idy = 0; idy < grid_height; ++idy)
{
for (size_t idx = 0; idx < grid_width; ++idx)
{
int rack_id = idx + 11;
int powerlevel = rack_id * (idy + 1);
powerlevel += grid_serial_number;
powerlevel *= rack_id;
string text = to_string(powerlevel);
powerlevel = text.size() >= 3 ? (text[text.size() - 3] - '0') : 0;
powerlevel -= 5;
grid[idx][idy] = powerlevel;
// cout << setw(4) << powerlevel;
}
// cout << "\n";
}
int top_value = numeric_limits<int>::min();
size_t top_size;
size_t top_x;
size_t top_y;
for (size_t size = 0; size != 300; ++size)
{
cout << "Size " << setw(3) << size << "/300\r" << flush;
for (size_t idx = 1; idx != (grid_width - (size - 1)); ++idx)
{
for (size_t idy = 0; idy != (grid_width - (size - 1)); ++idy)
{
int value = evaluate_square(grid, idx, idy, size);
if (value > top_value)
{
top_value = value;
top_size = size;
top_x = idx + 1;
top_y = idy + 1;
}
}
}
}
cout << "Top x,y,size is " << top_x << "," << top_y << "," << top_size
<< " with " << top_value << " power\n";
}

View file

@ -0,0 +1,3 @@
18
300
300

View file

@ -0,0 +1,34 @@
initial state: ##.######...#.##.#...#...##.####..###.#.##.#.##...##..#...##.#..##....##...........#.#.#..###.#
.###. => #
#.##. => .
.#.## => #
...## => .
###.# => #
##.## => .
..... => .
#..#. => #
..#.. => #
#.### => #
##.#. => .
..#.# => #
#.#.# => #
.##.# => #
.#..# => #
#..## => #
##..# => #
#...# => .
...#. => #
##### => .
###.. => #
#.#.. => .
....# => .
.#### => #
..### => .
..##. => #
.##.. => .
#.... => .
####. => #
.#.#. => .
.#... => #
##... => #

View file

@ -0,0 +1,127 @@
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
unordered_map<string, char> read_rules()
{
unordered_map<string, char> rules;
while(!cin.eof())
{
char result;
string rule;
cin >> rule;
cin.ignore(4); //ignore ' => '
cin >> result;
cin.ignore(1); //ignore '\n'
rules[rule] = result;
}
return rules;
}
vector<char> initial_state()
{
cin.ignore(15); // ignore 'initial state: '
string buf;
getline(cin, buf);
return vector<char>(buf.begin(), buf.end());
}
string environment(vector<char> const &plants, size_t idx)
{
string sig;
switch(idx)
{
case 0:
sig += "..";
sig += string(plants.begin(), plants.begin() + 3);
return sig;
case 1:
sig += ".";
sig += string(plants.begin(), plants.begin() + 4);
return sig;
default:
break;
}
if (idx == (plants.size() - 2))
{
auto it = plants.begin() + idx;
return string(it - 2, it + 2) + '.';
}
else if (idx == (plants.size() - 1))
{
auto it = plants.begin() + idx;
return string(it - 2, it + 1) + "..";
}
auto it = plants.begin() + idx;
return string(it - 2, it + 3);
}
int main()
{
int first = 0;
vector<char> plants = initial_state();
unordered_map<string, char> rules = read_rules();
string original = string(plants.begin(), plants.end());
cout << original << "\n";
for (size_t iterations = 20; iterations--; )
{
if (find(plants.begin(), plants.begin() + 3, '#')
!= plants.begin() + 3)
{
first -= 2;
plants.insert(plants.begin(), {'.', '.'});
}
if (find(plants.end() - 3, plants.end(), '#')
!= plants.end())
{
plants.insert(plants.end(), {'.', '.'});
}
vector<char> nextgen(plants.size(), '.');
// cout << "\n\n # now env new\n";
for (size_t idx = 0; idx != plants.size(); ++idx)
{
// cout << setw(3) << first + static_cast<int>(idx) << " ";
// cout << "[" << plants[idx] << "]: ";
string env = environment(plants, idx);
// cout << env << " => ";
char result = '?';
if (auto it = rules.find(env); it != rules.end())
result = it->second;
// cout << result << "\n";
nextgen[idx] = result;
}
plants.swap(nextgen);
}
// cout << string(-first, ' ') << original << "\n";
// cout << string(plants.begin(), plants.end()) << "\n";
int score = 0;
for (size_t idx = 0; idx < plants.size(); ++idx)
{
score += (plants[idx] == '#' ? idx + first : 0);
}
cout << "score: " << score << "\n";
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,250 @@
jplenqtlagxhivmwmscfukzodp
jbrehqtlagxhivmeyscfuvzodp
jbreaqtlagxzivmwysofukzodp
jxrgnqtlagxhivmwyscfukwodp
jbrenqtwagjhivmwysxfukzodp
jbrenqplagxhivmwyscfuazoip
jbrenqtlagxhivzwyscfldzodp
jbrefqtlagxhizmwyfcfukzodp
jbrenqtlagxhevmwfsafukzodp
jbrunqtlagxrivmsyscfukzodp
jbrenqtlaguhivmwyhlfukzodp
jbrcnstsagxhivmwyscfukzodp
jbrenqtlagozivmwyscbukzodp
jbrenqwlagxhivswysrfukzodp
jbrenstlagxhuvmiyscfukzodp
jbranqtlhgxhivmwysnfukzodp
jbrenqtvagxhinmxyscfukzodp
jbrenqtlagdhivmwyscfukxody
jbrenqtlagelavmwyscfukzodp
jbrenqtlagxhtvmwyhcfukzbdp
jbrenqwlagxhivmwyscfutzopp
jbrenqtlavxhibmtyscfukzodp
jbronqtlagxnivmwyscfuzzodp
jbredqtlagxhppmwyscfukzodp
jbrcnqtlogxhivmwysxfukzodp
jbremqtlagehivswyscfukzodp
jbrenqolagxhivmcyscfukzokp
jbrehqtlacxhgvmwyscfukzodp
fbrlnqtlagxhivmwyscbukzodp
zbrfnqtlagxhivrwyscfukzodp
jbregqtlagxnivmwyscfhkzodp
jbrenqtllgxnivmwystfukzodp
jurenqtlagxhivmwyscfulzoup
jbrenitdagxhivmwyxcfukzodp
jbrenqtlagxqivmwyscvuszodp
jbqenqwlagxhivmwyscfckzodp
jbrenqtlagxhivmwxscqupzodp
jbrenqtlagxhivmwysciuqiodp
jbrjnjtlagxhivmwyscfukzode
jbrenqtlagxhuvmwqscfukzods
jbrenqtlagxhuvmuyscfukzudp
ibrenqtlagxhivmwyscfuktokp
jbsenqtlagxhivcwyscfuksodp
jbrfnntlagxhivmwnscfukzodp
jzrenqulagxhivmwyscfukzodx
jbrenqtqygxhivmwyscfukzwdp
jbrenqtlagxfixmwyscfukzcdp
jbrenqaoagxhivmwyshfukzodp
jbrenqtlazxhivmworcfukzodp
jbrenqtlagxhicowyscfukrodp
jbrqnqtlagxhivzwyzcfukzodp
jbrenqtlalxhuvxwyscfukzodp
jbrenqtlqgxhhviwyscfukzodp
jbrenqtuggxhivmoyscfukzodp
jbrenqtlagxpivmwyscfukkodw
zbrenqhlagxhivmwyscdukzodp
jbrenutlagxxivmwyscfukzoqp
obrenqtlagxhivmwxscfuszodp
jbrenqtlagxhlvmwyscfuixodp
rbrenqtlagdhixmwyscfukzodp
jbrenqtlagxhivmwescfyszodp
jbrfnqtlagxhivmwyscaukzhdp
jbrenqtiagxhivmbyscfuxzodp
cbrrnqtuagxhivmwyscfukzodp
jbkenqtlagxhigmwysufukzodp
jbjewqtlagxhivmwyscfuqzodp
jbrznqtlagxvivmwyscfukzovp
jbrenttlacxhivmwyscfhkzodp
jblenqtlagxhivmwylcfukaodp
jbrenqtlagxhivmqysiftkzodp
jbrenqtlagwhikmwyscfukqodp
jbrenqtlegxhivmwvsckukzodp
jbrenqwzagxhiamwyscfukzodp
jbrenqtlagxhivcwyscfgkzodc
jbrenqtlagxxhvmwxscfukzodp
jbrenqtlngxhivmwyscfukoowp
jbreomtlagxhivmwpscfukzodp
jfrenqtlagxhivmwyscnumzodp
jbrenqtlagphipmwyscfukfodp
jvrenqtlagxhivmwyscfmkzodw
jbrenqtlaxxoiemwyscfukzodp
jbrenqtlagxhivmwyscemkzpdp
jbrenyjldgxhivmwyscfukzodp
jbrenqtlagxhivfvyspfukzodp
kbrenctlakxhivmwyscfukzodp
jbrmhqtlagxhivmwyscfuizodp
jbjenqtlagxlivmbyscfukzodp
jbrenqtlaaxhivmmyshfukzodp
jbronqtlagxhirmvyscfukzodp
jbcrnqtlagxwivmwyscfukzodp
jxrenszlagxhivmwyscfukzodp
jbpenqtlagxhivmwyscfukkody
jbrewqtlawxhivmwyscfukzhdp
jbrenqylagxhivmwlxcfukzodp
jbrenqtlagxxivtwywcfukzodp
jbrenqtlagxhcvgayscfukzodp
jbrenitlagxhivmwiscfukzohp
jbrenutlagxhivmwyscbukvodp
nbrenqtlagxhivmwysnfujzodp
jbrenqtlagxhivmwyqcfupzoop
jbrenqtrarxhijmwyscfukzodp
jbrenqtlagxhivmwysdfukzovy
jbrrnqtlagxhivmwyvcfukzocp
jbrenqtlagxhivmwyscfuvzzhp
jbhenitlagxhivmwysufukzodp
jbrenqtlagxhivmwyscfuwzoqx
kbrenqtlagxhivmwysqfdkzodp
jbrenqtlagxhivmwyxmfukzodx
jbcenatlagxxivmwyscfukzodp
jbrenhtlagvhdvmwyscfukzodp
jxrenqtlafxhivfwyscfukzodp
jbreaztlpgxhivmwyscfukzodp
tqrenqtlagxfivmwyscfukzodp
jbrenqgllgxhwvmwyscfukzodp
jbrejjtlagxhivmgyscfukzodp
jbrenqtlagxhivmwyscvukzoqv
jbrvnqtlagxsibmwyscfukzodp
jbrenqttagxhuvmwyscfukvodp
jbrenqteagxhivmwcscfukqodp
jbrenqtsabxhivmwyspfukzodp
jbbenqtlagxhivmwyscjukztdp
jnrenqtlagxhiimwydcfukzodp
jbrenqtlagxhfvmwyscxukzodu
jbrenqtluyxhiomwyscfukzodp
jbrenqvlagxhivmwyscuukzolp
ebrenqtlagxnivmwysrfukzodp
jbreeqtlatxhigmwyscfukzodp
jbrenqtvxgxhivmwyscfukzedp
jbrmnqtlagxhivmwywcfuklodp
jbreeqtvagxhivmwyscfukzody
jbrenptlagxhivmxyscfumzodp
jbrenqtlagxhivmwysgfukzfsp
jurenqtlagjhivmwkscfukzodp
jbrenntlagxhivmwtscffkzodp
jbrenqglagxhivmwyocfokzodp
wbrenqtlagxhivmwhscfukiodp
jbrenqtligxhivmqascfukzodp
jbrenqtlagxhivmwxscfukpojp
jurenqtlagxhivmmyscfbkzodp
jbrenqtmagxhivmwyscfrbzodp
jcrenqtlagxhivmwysefukzodm
jbrenqtlagxhicmwywcfukzodl
jbvanqtlagfhivmwyscfukzodp
jbmenqjlagxhivmwyscfdkzodp
jbrenqtlagohivvwysctukzodp
jbrenqtdagxdivmwyscfckzodp
kbrefqtlagxhivmwyscfuazodp
jbrwnqtoagxhivmwyswfukzodp
jjhenqtlagxhivmwyscfukzorp
jbgsnqtlagxhivkwyscfukzodp
jbrynqtlagxhivmsyspfukzodp
jbrenftlmkxhivmwyscfukzodp
nbrenqtxagxhmvmwyscfukzodp
jbrunqtlagxhijmwysmfukzodp
jbrenqtlagmaivmwyscfukzowp
jbrerqtlagxhihmwyscfukzudp
jbrenqtlagahivmwysckukzokp
kbrenqtlagxhirmwyscfupzodp
jbrrnqtlagxhivmwyecfukzodz
jbrenqtlavxhivmwyscfusiodp
jnrenqtlagxhivmwyhcfukzodw
jbretqtlagfhivmwyscfukzrdp
jbreoqtnagxhivmwyscfukzopp
jbrenbtllgxhivmwsscfukzodp
jbrenqtlmgxhivmwyscfuwzedp
jbnenqtlagxhivbwyscfukzokp
jbrenqslagxhivmvyscfukzndp
jbrenqtlagxzivmwuscfukztdp
gbrenqtlagxhyvmwyscfukjodp
jbrenqteagxhivmwyscfuszedp
jbrenqtlaglhivmwysafukkodp
jbrenqtlagxhcvmwascfukzogp
jbrenqtlagxhsvmkcscfukzodp
jbrenqslbgxhivmwyscfufzodp
cbrenqtlagxhivkwtscfukzodp
jbrenqtltgxhivmzyscfukzodj
jbrgnqtlagihivmwyycfukzodp
vbrenqauagxhivmwyscfukzodp
jbrqnqtlagjhivmwyscfqkzodp
jbrenqtlakxhivmwyscfukvobp
jcrenqelagxhivmwtscfukzodp
jbrrnqtlagxhlvmwyscfukzodw
jbrenqtlagxhivmwkscaumzodp
jbrenqdlagxhivmiescfukzodp
jhrenqtlagxhqvmwyscmukzodp
jbrenqtlaghhivmwyscfukkoyp
jowenqtlagxyivmwyscfukzodp
jbrenitaagxhivmwyscfqkzodp
jbrenqtlagxhivmwyscfnkbudp
jbyenqtlagxhivmiyscfukzhdp
jbrenitlagxhibjwyscfukzodp
jbrenqtlavxhjvmwpscfukzodp
jbrenqyaagxhivmwyscflkzodp
jbrenqylagxhivmwyicfupzodp
jbrenqtlagxmevmwylcfukzodp
lbrenqtlagxhiqmwyscfikzodp
jbrenqtnarxhivmwyscfmkzodp
jbrenqtlamxhivmwyscfnkzorp
jbbenqtlavxhivmwyscjukztdp
jbrenqtlagxhivmwyscfnliodp
jbwenetlagxhivmwyscfukzodt
jbrenatlagxhivmwysmfujzodp
jbrsnstlagxhivmwyscfukgodp
jbwvnitlagxhivmwyscfukzodp
jbrenqtbagxhkvmwypcfukzodp
jbrlnqtlafxhivmwyscfukdodp
jbrenztlanxhivmwyscjukzodp
jbrepqtlagxhivmwudcfukzodp
jbrenqtlagxiivmwdscfskzodp
jbrdjqtlagxhivmwyschukzodp
jbrenqtoaguhivmwyccfukzodp
jdrexqjlagxhivmwyscfukzodp
jbrenqtlagxhovmwysckukaodp
pbrfnqblagxhivmwyscfukzodp
jbrenqtlagxrivgiyscfukzodp
jbrelqtgagxhivmryscfukzodp
jbrenqtlagxhicmwjscfikzodp
jbrenqjlagxhivmwyscfmkjodp
jbrenqtlagxpivmwzscgukzodp
jbienqzlagxpivmwyscfukzodp
jbrenqvlagxhivmwdscfukzodx
owrenqtlagxhivmwyicfukzodp
gbrenqtlaathivmwyscfukzodp
jbgenqtlafxhivmwysqfukzodp
jbrenqtlagxhivtwsscfukzokp
jbrnnqylanxhivmwyscfukzodp
ebrenqolagxhivmcyscfukzodp
jbrenqtlarnhivgwyscfukzodp
jbmenqtlagxhivmvyscfukzgdp
jbrevqtlaglhivmwystfukzodp
jbrenqplanthivmwyscfukzodp
jbrenqtlagxhivmkyscbukzosp
jbrenqtlagxaivmwyscfugzodo
jbrenqplagxhnvmwyscfjkzodp
jbrenqtlagxhivgwyscfusrodp
cbrenqtlagxhivmwysmfukzody
jbrenquwaexhivmwyscfukzodp
jbredqtlagxhdvmwyscfukzoup
jbrxnqtlagxhivmwysczukaodp
jbrenqtlafnhivmwyscfuczodp
jbbdkqtlagxhivmwyscfukzodp
ubrenqtlagxhivkwyucfukzodp
ebjenqtlagxhivmwyscfukzodj
jbgenqtlugxxivmwyscfukzodp
jbrenqtoagxqivmwdscfukzodp
bbeenqtlagxhivmwyscfumzodp
jbfeeqtlagxhivmwmscfukzodp
jbrlnqtlagxhiimwescfukzodp
jbrenqtlagwoivmwyscfukhodp
jbrenqtlagnhivmwyscfuszovp

View file

@ -0,0 +1,40 @@
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main()
{
size_t dubbles = 0;
size_t tripples = 0;
string buffer;
while(getline(cin, buffer))
{
bool twice = false;
bool thrice = false;
size_t letters[26] = { };
for (char c : buffer)
{
++letters[c - 'a'];
}
for (size_t idx = 0; idx < 26; ++idx)
{
if (letters[idx] == 2)
twice = true;
if (letters[idx] == 3)
thrice = true;
}
if (twice)
++dubbles;
if (thrice)
++tripples;
}
cout << "checsum: " << dubbles * tripples << "\n";
}

View file

@ -0,0 +1,56 @@
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
size_t label_diff(string const &lhs, string const &rhs)
{
size_t diff = 0;
for (size_t idx = 0; idx != lhs.size(); ++idx)
diff += lhs[idx] - rhs[idx] ? 1 : 0;
return diff;
}
string equal_part(string const &lhs, string const &rhs)
{
string rval;
rval.reserve(lhs.size() - 1);
for (size_t idx = 0; idx != lhs.size(); ++idx)
{
if (lhs[idx] == rhs[idx])
rval.push_back(lhs[idx]);
}
return rval;
}
int main()
{
size_t dubbles = 0;
size_t tripples = 0;
string buffer;
vector<string> labels;
while (getline(cin, buffer))
labels.push_back(buffer);
for (string const &lhs : labels)
{
for (string const &rhs : labels)
{
size_t difference = label_diff(rhs, lhs);
if (difference == 1)
{
cout << "Equal part: " << equal_part(lhs, rhs) << "\n";
return 0;
}
}
}
}
//jbbenqtlaxhivmwyscjukztdp correct

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,137 @@
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Star
{
int x;
int y;
int z;
int t;
};
istream& operator>>(istream& in, Star &star)
{
in >> star.x;
in.ignore(); //ignore ','
in >> star.y;
in.ignore();
in >> star.z;
in.ignore();
in >> star.t;
in.ignore();
return in;
}
ostream &operator<<(ostream &out, Star const &star)
{
out << "[" << star.x << ", " << star.y << ", " << star.z << ", " << star.t << "]";
return out;
}
size_t distance(Star const &lhs, Star const &rhs)
{
int dist = abs(lhs.x - rhs.x)
+ abs(lhs.y - rhs.y)
+ abs(lhs.z - rhs.z)
+ abs(lhs.t - rhs.t);
return dist;
}
bool in_cluster(vector<Star> const &cluster, Star const &star)
{
for (Star clst : cluster)
{
if (distance(clst, star) <= 3)
return true;
}
return false;
}
bool same_cluster(vector<Star> const &lhs, vector<Star> const &rhs)
{
for (Star left : lhs)
{
for (Star right : rhs)
{
if (distance(left, right) <= 3)
return true;
}
}
return false;
}
int main()
{
vector<Star> stars;
while (cin)
{
Star star;
cin >> star;
stars.push_back(star);
}
// kickstart 1st cluster
vector<vector<Star>> clusters;
for (Star star : stars)
{
bool matched = false;
for (vector<Star> &cluster : clusters)
{
if (in_cluster(cluster, star))
{
cluster.push_back(star);
matched = true;
break;
}
}
if (!matched)
{
clusters.push_back({});
clusters.back().push_back(star);
}
}
bool merged = true;
while (merged)
{
merged = false;
for (size_t idx = 0; idx < clusters.size(); ++idx)
{
for (size_t jdx = idx + 1; jdx < clusters.size(); ++jdx)
{
if (same_cluster(clusters[idx], clusters[jdx]))
{
clusters[idx].insert(clusters[idx].end(), clusters[jdx].begin(), clusters[jdx].end());
clusters.erase(clusters.begin() + jdx);
merged = true;
break;
}
}
if (merged) break;
}
}
for (vector<Star> cluster : clusters)
{
cout << "\n\nCluster:\n";
for (Star star : cluster)
{
cout << " Star: " << star << "\n";
}
}
cout << "Num clusters: " << clusters.size() << "\n";
}

View file

@ -0,0 +1,10 @@
1,-1,0,1
2,0,-1,0
3,2,-1,0
0,0,3,1
0,0,-1,-1
2,3,-2,0
-2,2,0,0
2,-2,0,-1
1,-1,0,-1
3,2,0,2

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,83 @@
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Claim
{
size_t id;
size_t px;
size_t py;
size_t width;
size_t height;
};
istream &operator>>(istream &in, Claim &claim)
{
// reading into char in favor if in.ignore(), to automatically
// toss any present whitespace.
char at;
cin >> at; //ignore '#'
in >> claim.id;
in >> at; //ignore '@'
in >> claim.px;
cin >> at; //ignore ','
in >> claim.py;
in >> at; //ignore ':'
in >> claim.width;
in >> at; //ignore 'x'
in >> claim.height;
return in;
}
void layout_claim(vector<vector<int>> &canvas, Claim const &claim)
{
size_t end_x = claim.px + claim.width;
size_t end_y = claim.py + claim.height;
for (size_t px = claim.px; px != end_x; ++px)
{
for (size_t py = claim.py; py != end_y; ++py)
++canvas[px][py];
}
}
int main()
{
size_t total_width = 0;
size_t total_height = 0;
vector<Claim> claims;
vector<vector<int>> canvas;
while (!cin.eof())
{
Claim claim;
cin >> claim;
total_width = max(total_width, claim.px + claim.width);
total_height = max(total_height, claim.py + claim.height);
claims.push_back(claim);
}
canvas.resize(total_width, vector<int>(total_height, 0));
for (Claim const &claim : claims)
layout_claim(canvas, claim);
size_t overlap = 0;
for (size_t py = 0; py < total_height; ++py)
{
for (size_t px = 0; px < total_width; ++px)
{
if (canvas[px][py] > 1)
++overlap;
}
}
cout << "Overlap: " << overlap << "\n";
}

View file

@ -0,0 +1,105 @@
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Claim
{
size_t id;
size_t px;
size_t py;
size_t width;
size_t height;
};
istream &operator>>(istream &in, Claim &claim)
{
// reading into char in favor if in.ignore(), to automatically
// toss any present whitespace.
char at;
cin >> at; //ignore '#'
in >> claim.id;
in >> at; //ignore '@'
in >> claim.px;
cin >> at; //ignore ','
in >> claim.py;
in >> at; //ignore ':'
in >> claim.width;
in >> at; //ignore 'x'
in >> claim.height;
return in;
}
void layout_claim(vector<vector<int>> &canvas, Claim const &claim)
{
size_t end_x = claim.px + claim.width;
size_t end_y = claim.py + claim.height;
for (size_t px = claim.px; px != end_x; ++px)
{
for (size_t py = claim.py; py != end_y; ++py)
++canvas[px][py];
}
}
bool overlaps(vector<vector<int>> &canvas, Claim const &claim)
{
size_t end_x = claim.px + claim.width;
size_t end_y = claim.py + claim.height;
for (size_t px = claim.px; px != end_x; ++px)
{
for (size_t py = claim.py; py != end_y; ++py)
{
if (canvas[px][py] != 1)
return true;
}
}
return false;
}
int main()
{
size_t total_width = 0;
size_t total_height = 0;
vector<Claim> claims;
vector<vector<int>> canvas;
while (!cin.eof())
{
Claim claim;
cin >> claim;
total_width = max(total_width, claim.px + claim.width);
total_height = max(total_height, claim.py + claim.height);
claims.push_back(claim);
}
canvas.resize(total_width, vector<int>(total_height, 0));
for (Claim const &claim : claims)
layout_claim(canvas, claim);
size_t overlap = 0;
for (size_t py = 0; py < total_height; ++py)
{
for (size_t px = 0; px < total_width; ++px)
{
if (canvas[px][py] > 1)
++overlap;
}
}
for (size_t idx = 0; idx != claims.size(); ++idx)
{
if (!overlaps(canvas, claims[idx]))
cout << "No overlap for " << idx << "\n";
}
}

View file

@ -0,0 +1,3 @@
#1 @ 1,3: 4x4
#2 @ 3,1: 4x4
#3 @ 5,5: 2x2

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,159 @@
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
struct Event
{
tm time;
string event;
};
istream &operator>>(istream &in, Event &event)
{
char toss;
in >> toss; // toss '['
in >> event.time.tm_year;
event.time.tm_year -= 1900;
in >> toss; // toss '-'
in >> event.time.tm_mon;
in >> toss; // toss '-'
in >> event.time.tm_mday;
in >> event.time.tm_hour;
in >> toss; // toss ':'
in >> event.time.tm_min;
in >> toss; // toss ']'
getline(cin, event.event);
return in;
}
ostream &operator<<(ostream &out, Event const &event)
{
out << "Event: \n";
out << " " << put_time(&event.time, "%c") << "\n";
out << " - " << event.event << "\n";
return out;
}
int main()
{
vector<Event> events;
map<int, int[60]> guards;
cout << setfill(' ');
while(!cin.eof())
{
Event event{};
cin >> event;
events.push_back(event);
}
std::sort(events.begin(), events.end(),
[](Event &lhs, Event &rhs)
{
time_t l_time = mktime(&lhs.time);
time_t r_time = mktime(&rhs.time);
return l_time < r_time;
});
int current_id;
for (Event const &event : events)
{
size_t numstart = event.event.find("#");
if (numstart != string::npos)
{
size_t end = event.event.find(" ", numstart);
current_id = stoi(event.event.substr(numstart + 1, end - numstart - 1));
}
else if (event.event.find("asleep") != string::npos)
{
for (size_t idx = event.time.tm_min; idx != 60; ++idx)
++guards[current_id][idx];
}
else if (event.event.find("wakes") != string::npos)
{
for (size_t idx = event.time.tm_min; idx != 60; ++idx)
--guards[current_id][idx];
}
}
size_t max_id = 0;
size_t sleeper = 0;
// cout << " Guard ID Minute\n";
// cout << " 1 2 3 4 5\n";
// cout << " 012345678901234567890123456789012345678901234567890123456789\n";
cout << " ";
for (size_t idx = 0; idx != 60; ++idx)
cout << setw(3) << idx;
cout << " | total\n";
for (auto const &[id, sleep] : guards)
{
cout << "Guard " << setw(5) << id << ": ";
size_t total = 0;
for (int num : sleep)
{
cout << setw(3) << num;
total += num;
}
cout << " | " << total << "\n";
if (total > sleeper)
{
max_id = id;
sleeper = total;
}
}
cout << "Max sleeper: " << max_id << "\n";
size_t min_id = 0;
sleeper = 0;
for (size_t idx = 0; idx != 60; ++idx)
{
if (guards[max_id][idx] > sleeper)
{
sleeper = guards[max_id][idx];
min_id = idx;
}
}
cout << "Slept most in minute " << min_id << ", for " << sleeper << " minutes.\n";
sleeper = 0;
min_id = 0;
size_t minute = 0;
for (auto const &[id, sleep] : guards)
{
for (size_t idx = 0; idx != 60; ++idx)
{
if (sleep[idx] >= sleeper)
{
sleeper = sleep[idx];
min_id = id;
minute = idx;
}
}
}
cout << "Guard " << min_id << " is most frequently asleep on minute ";
cout << minute << "\n";
cout << sleeper * minute << "\n";
}

View file

@ -0,0 +1,17 @@
[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

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,56 @@
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
size_t collapse_polymer(vector<char> polymer)
{
int react_diff = abs('a' - 'A');
size_t oldsize = 0;
while(oldsize != polymer.size())
{
oldsize = polymer.size();
for (size_t idx = 0; idx < polymer.size() - 1; ++idx)
{
if (abs(polymer[idx] - polymer[idx + 1]) == react_diff)
{
polymer.erase(polymer.begin() + idx, polymer.begin() + idx + 2);
--idx;
}
}
}
return polymer.size();
}
int main()
{
vector<char> polymer {
istreambuf_iterator<char>(cin),
istreambuf_iterator<char>()
};
cout << "Read polymer of size: " << polymer.size() << "\n";
size_t minsize = polymer.size();
for (size_t idx = 0; idx < 26; ++idx)
{
char current = 'a' + idx;
vector<char> filtered{polymer};
auto it = remove_if(filtered.begin(), filtered.end(), [=](char c)
{
if (c == current || c == toupper(current))
return true;
return false;
});
filtered.erase(it, filtered.end());
minsize = min(collapse_polymer(filtered), minsize);
}
cout << "Smallest collapsed polymer size: " << minsize << "\n";
}

View file

@ -0,0 +1,50 @@
118, 274
102, 101
216, 203
208, 251
309, 68
330, 93
91, 179
298, 278
201, 99
280, 272
141, 312
324, 290
41, 65
305, 311
198, 68
231, 237
164, 224
103, 189
216, 207
164, 290
151, 91
166, 250
129, 149
47, 231
249, 100
262, 175
299, 237
62, 288
228, 219
224, 76
310, 173
80, 46
312, 65
183, 158
272, 249
57, 141
331, 191
163, 359
271, 210
142, 137
349, 123
55, 268
160, 82
180, 70
231, 243
133, 353
246, 315
164, 206
229, 97
268, 94

View file

@ -0,0 +1,125 @@
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Point
{
size_t x;
size_t y;
Point()
: x(0), y(0)
{ }
Point(size_t x, size_t y)
: x(x), y(y)
{ }
};
istream &operator>>(istream& in, Point &point)
{
cin >> point.x;
cin.ignore(); // ignore ','
cin >> point.y;
return in;
}
inline size_t manhattan_distance(Point const &p1, Point const &p2)
{
return (p1.x > p2.x ? p1.x - p2.x : p2.x - p1.x)
+ (p1.y > p2.y ? p1.y - p2.y : p2.y - p1.y);
}
int closest(Point location, vector<Point> const &points)
{
int index = -1;
size_t mindist = std::numeric_limits<size_t>::max();
for (size_t idx = 0; idx != points.size(); ++idx)
{
size_t distance = manhattan_distance(location, points[idx]);
if (distance == mindist)
index = -1;
else if (distance < mindist)
{
mindist = distance;
index = idx;
}
}
return index;
}
int main()
{
size_t width = 0;
size_t height = 0;
vector<Point> points;
while(!cin.eof())
{
Point point;
cin >> point;
points.push_back(point);
width = max(width, point.x + 1);
height = max(height, point.y + 1);
}
cout << "grid size: " << width << " x " << height << "\n";
vector<int> counts(points.size(), 0);
for (size_t idx = 0; idx != width; ++idx)
{
for (size_t idy = 0; idy != height; ++idy)
{
int index = closest(Point{idx, idy}, points);
if (index == -1) continue;
++counts[index];
}
}
// if a class hits the edge its infinite.
// we check highest and lowers rows first.
for (size_t idx = 0; idx != width; ++idx)
{
int index = closest(Point{idx, 0}, points);
int index2 = closest(Point{idx, height - 1}, points);
if (index != -1)
counts[index] = -1;
if (index2 != -1)
counts[index2] = -1;
}
//side rows
for (size_t idx = 0; idx != height; ++idx)
{
int index = closest(Point{0, idx}, points);
int index2 = closest(Point{width - 1, idx}, points);
if (index != -1)
counts[index] = -1;
if (index2 != -1)
counts[index2] = -1;
}
size_t maxclass = 0;
int space = counts[0];
for (size_t idx = 1; idx != counts.size(); ++idx)
{
if (counts[idx] > space)
{
space = counts[idx];
maxclass = idx;
}
}
cout << "biggest class is " << maxclass << " with a size of " << space << "\n";
}

View file

@ -0,0 +1,73 @@
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Point
{
size_t x;
size_t y;
Point()
: x(0), y(0)
{ }
Point(size_t x, size_t y)
: x(x), y(y)
{ }
};
istream &operator>>(istream& in, Point &point)
{
cin >> point.x;
cin.ignore(); // ignore ','
cin >> point.y;
return in;
}
inline size_t manhattan_distance(Point const &p1, Point const &p2)
{
return (p1.x > p2.x ? p1.x - p2.x : p2.x - p1.x)
+ (p1.y > p2.y ? p1.y - p2.y : p2.y - p1.y);
}
int main()
{
size_t width = 0;
size_t height = 0;
vector<Point> points;
while(!cin.eof())
{
Point point;
cin >> point;
points.push_back(point);
width = max(width, point.x + 1);
height = max(height, point.y + 1);
}
size_t region_size = 0;
size_t distance_limit = 10000;
for (size_t idx = 0; idx != width; ++idx)
{
for (size_t idy = 0; idy != height; ++idy)
{
size_t sum = 0;
Point current {idx, idy};
for_each(points.begin(), points.end(), [&](Point const &point)
{
sum += manhattan_distance(current, point);
});
if (sum < distance_limit)
region_size++;
}
}
cout << "region size: " << region_size << "\n";
}

View file

@ -0,0 +1,101 @@
Step J must be finished before step K can begin.
Step N must be finished before step X can begin.
Step S must be finished before step G can begin.
Step T must be finished before step R can begin.
Step H must be finished before step L can begin.
Step V must be finished before step W can begin.
Step G must be finished before step U can begin.
Step K must be finished before step A can begin.
Step D must be finished before step Z can begin.
Step C must be finished before step E can begin.
Step X must be finished before step P can begin.
Step Y must be finished before step U can begin.
Step R must be finished before step O can begin.
Step W must be finished before step U can begin.
Step O must be finished before step Q can begin.
Step A must be finished before step P can begin.
Step B must be finished before step E can begin.
Step F must be finished before step E can begin.
Step Q must be finished before step U can begin.
Step M must be finished before step E can begin.
Step P must be finished before step U can begin.
Step L must be finished before step Z can begin.
Step Z must be finished before step U can begin.
Step U must be finished before step E can begin.
Step I must be finished before step E can begin.
Step H must be finished before step G can begin.
Step X must be finished before step I can begin.
Step K must be finished before step X can begin.
Step Z must be finished before step I can begin.
Step S must be finished before step M can begin.
Step L must be finished before step U can begin.
Step A must be finished before step M can begin.
Step W must be finished before step A can begin.
Step N must be finished before step A can begin.
Step S must be finished before step E can begin.
Step W must be finished before step Q can begin.
Step J must be finished before step L can begin.
Step Q must be finished before step L can begin.
Step M must be finished before step U can begin.
Step H must be finished before step E can begin.
Step D must be finished before step E can begin.
Step V must be finished before step P can begin.
Step Q must be finished before step M can begin.
Step X must be finished before step W can begin.
Step K must be finished before step I can begin.
Step T must be finished before step H can begin.
Step Y must be finished before step L can begin.
Step G must be finished before step O can begin.
Step M must be finished before step Z can begin.
Step F must be finished before step Z can begin.
Step Q must be finished before step E can begin.
Step H must be finished before step C can begin.
Step Q must be finished before step P can begin.
Step D must be finished before step U can begin.
Step Z must be finished before step E can begin.
Step O must be finished before step M can begin.
Step L must be finished before step I can begin.
Step J must be finished before step A can begin.
Step Q must be finished before step Z can begin.
Step P must be finished before step I can begin.
Step K must be finished before step O can begin.
Step R must be finished before step E can begin.
Step W must be finished before step F can begin.
Step D must be finished before step Q can begin.
Step R must be finished before step U can begin.
Step W must be finished before step P can begin.
Step S must be finished before step Z can begin.
Step T must be finished before step P can begin.
Step B must be finished before step Q can begin.
Step S must be finished before step T can begin.
Step R must be finished before step A can begin.
Step K must be finished before step R can begin.
Step N must be finished before step G can begin.
Step C must be finished before step W can begin.
Step T must be finished before step A can begin.
Step B must be finished before step Z can begin.
Step C must be finished before step P can begin.
Step D must be finished before step P can begin.
Step B must be finished before step P can begin.
Step F must be finished before step U can begin.
Step V must be finished before step X can begin.
Step K must be finished before step W can begin.
Step Y must be finished before step I can begin.
Step C must be finished before step B can begin.
Step X must be finished before step L can begin.
Step X must be finished before step M can begin.
Step H must be finished before step P can begin.
Step S must be finished before step F can begin.
Step J must be finished before step Y can begin.
Step Y must be finished before step Z can begin.
Step B must be finished before step I can begin.
Step S must be finished before step C can begin.
Step K must be finished before step E can begin.
Step N must be finished before step Q can begin.
Step A must be finished before step Z can begin.
Step J must be finished before step I can begin.
Step Y must be finished before step O can begin.
Step Y must be finished before step F can begin.
Step S must be finished before step U can begin.
Step D must be finished before step W can begin.
Step V must be finished before step D can begin.

View file

@ -0,0 +1,63 @@
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Constraint
{
bool placed = false;
vector<char> requires;
vector<char> required_by;
};
bool satisfied(Constraint const &constraint, string const &plan)
{
for (char c : constraint.requires)
{
if (plan.find(c) == string::npos)
return false;
}
return true;
}
int main()
{
array<Constraint, 26> constraints {};
while (!cin.eof())
{
char step;
char requires;
cin.ignore(5); // 'Step '
cin >> requires;
cin.ignore(30); // ' must be finished before step '
cin >> step;
cin.ignore(12); //' can begin.\n'
cout << step << " requires " << requires << "\n";
constraints[step - 'A'].requires.push_back(requires);
constraints[requires - 'A'].required_by.push_back(step);
}
string plan;
while(plan.size() != 26)
{
for (size_t idx = 0; idx < 26; ++idx)
{
if (!constraints[idx].placed && satisfied(constraints[idx], plan))
{
plan += static_cast<char>('A' + idx);
constraints[idx].placed = true;
break;
}
}
cout << plan.size() << " / '" << plan << "'\n";
}
cout << plan.size() << " / '" << plan << "'\n";
}

View file

@ -0,0 +1,142 @@
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <chrono>
#include <thread>
#include <unistd.h>
using namespace std;
struct Constraint
{
bool placed = false;
vector<char> requires;
vector<char> required_by;
};
struct Task
{
char step = '\0';
size_t time_left = 0;
};
bool satisfied(Constraint const &constraint, string const &plan)
{
for (char c : constraint.requires)
{
if (plan.find(c) == string::npos)
{
cout << "Constraint not met in plan '" << plan << "', missing " << c << "\n";
return false;
}
}
return true;
}
char find_satisfied(array<Constraint, 26> const &constraints, string const&plan, string const&goal)
{
cout << "Finding next step from plan '" << plan << "', already done: '" << goal << "'\n";
for (char c : plan)
{
if (satisfied(constraints[c - 'A'], goal))
return c;
}
return 0;
}
int main()
{
array<Constraint, 26> constraints {};
size_t plansize = 26;
size_t baseline = 60;
while (!cin.eof())
{
char step;
char requires;
cin.ignore(5); // 'Step '
cin >> requires;
cin.ignore(30); // ' must be finished before step '
cin >> step;
cin.ignore(12); //' can begin.\n'
cout << step << " requires " << requires << "\n";
constraints[step - 'A'].requires.push_back(requires);
constraints[requires - 'A'].required_by.push_back(step);
}
string plan;
while(plan.size() != plansize)
{
for (size_t idx = 0; idx < 26; ++idx)
{
if (!constraints[idx].placed && satisfied(constraints[idx], plan))
{
plan += static_cast<char>('A' + idx);
constraints[idx].placed = true;
break;
}
}
cout << plan.size() << " / '" << plan << "'\n";
}
cout << plan.size() << " / '" << plan << "'\n";
/************************************/
/************************************/
/************************************/
string done;
Task workers[5];
size_t duration = 0;
while (done.size() != plansize)
{
++duration;
for(Task &task : workers)
if (task.time_left != 0) --task.time_left;
for (Task &task : workers)
{
if (task.time_left == 0 && task.step != '\0')
{
done += task.step;
task.step = '\0';
}
}
for (Task &task : workers)
{
char next = find_satisfied(constraints, plan, done);
if (next == 0) break;
if (task.time_left == 0)
{
if (plan.size() > 0 && satisfied(constraints[next - 'A'], done))
{
task.time_left = baseline + (next - 'A') + 1;
task.step = next;
plan.erase(plan.find(next), 1);
}
}
}
cout << "Plan / Done: '" << plan << "' / '" << done << "'\n";
cout << "Workers on: \n";
for (Task &task : workers)
{
cout << " Step: " << (task.step == '\0' ? '-' : task.step) << "\n";
cout << " Time: " << task.time_left << "\n";
}
cout << "\n";
// this_thread::sleep_for(std::chrono::milliseconds(1000));
}
cout << "Total time: " << duration << "s \n";
}

View file

@ -0,0 +1,7 @@
Step C must be finished before step A can begin.
Step C must be finished before step F can begin.
Step A must be finished before step B can begin.
Step A must be finished before step D can begin.
Step B must be finished before step E can begin.
Step D must be finished before step E can begin.
Step F must be finished before step E can begin.

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,83 @@
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
struct Node
{
size_t child_count;
size_t metadata_count;
vector<Node> children;
vector<int> metadata;
Node()
: child_count(0), metadata_count(0)
{ }
};
size_t metadata_sum = 0;
Node parse_node(vector<int> &data)
{
Node rval;
rval.child_count = data.back();
data.pop_back();
rval.metadata_count = data.back();
data.pop_back();
for (size_t idx = 0; idx != rval.child_count; ++idx)
{
rval.children.push_back(parse_node(data));
}
for (size_t idx = 0; idx != rval.metadata_count; ++idx)
{
rval.metadata.push_back(data.back());
data.pop_back();
metadata_sum += rval.metadata.back();
}
return rval;
}
size_t node_value(Node const &node)
{
if (node.children.empty())
{
return accumulate(node.metadata.begin(), node.metadata.end(), 0);
}
size_t sum = 0;
for (int idx : node.metadata)
{
int index = idx - 1;
if (index >= node.children.size())
continue;
sum += node_value(node.children[index]);
}
return sum;
}
int main()
{
vector<int> data;
while(!cin.eof())
{
int tmp;
cin >> tmp;
data.push_back(tmp);
}
vector<int> copy(data.rbegin(), data.rend()); //reverse data
Node root = parse_node(copy);
cout << "metadata sum: " << metadata_sum << "\n"; // answer to 1
cout << "node value: " << node_value(root) << "\n"; // answer to 2
}

View file

@ -0,0 +1 @@
2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2

View file

@ -0,0 +1 @@
468 players; last marble is worth 7184300 points

View file

@ -0,0 +1,120 @@
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
/* Slow-as-fuck solution:
$ time ./a.out < input.in
Num players: 468
Last marble: 7184300
Best player had a score of 3156297594
./a.out < input.in 5143.54s user 1.02s system 99% cpu 1:25:53.91 total
*/
struct Game
{
size_t num_players;
size_t last_marble;
};
istream &operator>>(istream &in, Game &game)
{
cin >> game.num_players;
cin.ignore(31); // ignore ' players; last marble is worth '.
cin >> game.last_marble;
cin.ignore(8); // ignore ' points\n'
return in;
}
size_t index(size_t main, size_t size)
{
main += 2;
main = main % size;
return main;
}
void print_gamestate(size_t round, vector<size_t> const &game, size_t main)
{
cout << setw(7) << ("["s + to_string(round) + "]: "s);
for (size_t idx = 0; idx != game.size(); ++idx)
{
if (idx == main)
cout << setw(5) << ("("s + to_string(game[idx]) + ")"s);
else
cout << setw(5) << game[idx];
}
cout << "\n";
}
size_t insert_marble(vector<size_t> *game, size_t main, size_t marble)
{
size_t before = (main + 2) % game->size();
if (before == 0)
{
game->push_back(marble);
return game->size() - 1;
}
game->insert(game->begin() + before, marble);
return before;
}
size_t bonus_marble(size_t main, size_t size)
{
if (main < 7)
return size - (7 - main);
return main - 7;
}
int main()
{
Game game;
cin >> game;
cout << "Num players: " << game.num_players << "\n";
cout << "Last marble: " << game.last_marble << "\n";
size_t main_marble = 0;
vector<size_t> players;
players.resize(game.num_players, 0);
vector<size_t> marbles { 0 };
// print_gamestate(0, marbles, main_marble);
for (size_t idx = 1; idx != game.last_marble + 1; ++idx)
{
cout << "Progress: " << idx / static_cast<float>(game.last_marble) * 100 << "\r";
if (idx % 23 == 0) //special case
{
size_t player = (idx - 1) % game.num_players;
players[player] += idx;
main_marble = bonus_marble(main_marble, marbles.size());
players[player] += marbles[main_marble];
marbles.erase(marbles.begin() + main_marble);
}
else
{
main_marble = insert_marble(&marbles, main_marble, idx);
}
// print_gamestate(idx, marbles, main_marble);
}
size_t best_player = 0;
for (size_t idx = 1; idx < players.size(); ++idx)
{
if (players[best_player] < players[idx])
best_player = idx;
}
cout << "Best player had a score of " << players[best_player] << "\n";
}

View file

@ -0,0 +1,146 @@
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
/*
$ time ./a.out < input.in
Num players: 468
Last marble: 7184300
Highest reached score: 3156297594
./a.out < input.in 0.16s user 0.05s system 99% cpu 0.203 total
*/
struct Game
{
size_t num_players;
size_t last_marble;
};
istream &operator>>(istream &in, Game &game)
{
cin >> game.num_players;
cin.ignore(31); // ignore ' players; last marble is worth '.
cin >> game.last_marble;
cin.ignore(8); // ignore ' points\n'
return in;
}
struct List
{
size_t marble;
List *next;
List *previous;
List(size_t num)
: marble(num), next(this), previous(this)
{ }
List *rotate(int direction)
{
List *rval = this;
if (direction > 0)
{
for (; direction--; )
rval = rval->next;
}
else
{
direction *= -1;
for (; direction--; )
rval = rval->previous;
}
return rval;
}
List* insert_after(List *entry) //assume single entry
{
entry->next = next;
entry->next->previous = entry;
entry->previous = this;
next = entry;
return entry;
}
//returns next in list. or nullptr when list size == 1
List* remove_current()
{
if (next == this)
{
delete this;
return nullptr;
}
next->previous = previous;
previous->next = next;
List *rval = next;
delete this;
return rval;
}
void print_list()
{
List *current = next;
cout << setw(5) << marble;
while (current != this)
{
cout << setw(5) << current->marble;
current = current->next;
}
}
};
int main()
{
Game game;
cin >> game;
cout << "Num players: " << game.num_players << "\n";
cout << "Last marble: " << game.last_marble << "\n";
List *root = new List(0);
List *main = root;
vector<size_t> players;
players.resize(game.num_players, 0);
for (size_t idx = 1; idx < game.last_marble + 1; ++idx)
{
if (idx % 23 == 0)
{
size_t player = (idx + 1) % game.num_players;
players[player] += idx;
main = main->rotate(-7); //?
players[player] += main->marble;
main = main->remove_current();
}
else
{
main = main->rotate(1)->insert_after(new List(idx));
}
}
size_t player = 0;
for (size_t idx = 0; idx < game.num_players; ++idx)
{
if (players[player] < players[idx])
player = idx;
}
cout << "Highest reached score: " << players[player] << "\n";
while(root)
root = root->remove_current();
}

View file

@ -0,0 +1 @@
10 players; last marble is worth 1618 points