diff options
author | Yigit Sever | 2021-12-13 10:40:39 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-13 10:40:39 +0300 |
commit | bf16b19b1f6deffd1983efca059db576f3b60ee5 (patch) | |
tree | 1262f68d8eb2c326684d395aebcd5a1cc0b0f748 /2019 | |
parent | 74b27ccca31bb757c737dd7fdc02f513f57561b2 (diff) | |
download | aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.gz aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.bz2 aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.zip |
2019, tracking
Diffstat (limited to '2019')
-rw-r--r-- | 2019/day1/README.md | 5 | ||||
-rw-r--r-- | 2019/day1/part1.in | 100 | ||||
-rw-r--r-- | 2019/day1/part2.in | 100 | ||||
-rw-r--r-- | 2019/day1/rec_fuel.py | 23 | ||||
-rw-r--r-- | 2019/day2/1202.in | 1 | ||||
-rw-r--r-- | 2019/day2/intcode.pl | 57 | ||||
-rw-r--r-- | 2019/day3/part1.in | 2 | ||||
-rw-r--r-- | 2019/day3/smalltest.in | 2 | ||||
-rw-r--r-- | 2019/day3/wires.pl | 68 | ||||
-rw-r--r-- | 2019/day4/password.lp | 17 | ||||
-rw-r--r-- | 2019/day4/password.pl | 29 | ||||
-rw-r--r-- | 2019/day5/intcode.pl | 92 | ||||
-rw-r--r-- | 2019/day5/part1.in | 1 | ||||
-rw-r--r-- | 2019/day6/orbits.pl | 39 | ||||
-rw-r--r-- | 2019/day6/orbits.py | 28 | ||||
-rw-r--r-- | 2019/day6/part1.in | 1069 | ||||
-rw-r--r-- | 2019/day7/comm.py | 19 | ||||
-rw-r--r-- | 2019/day7/intcode.pl | 109 | ||||
-rw-r--r-- | 2019/day7/part1.in | 1 |
19 files changed, 1762 insertions, 0 deletions
diff --git a/2019/day1/README.md b/2019/day1/README.md new file mode 100644 index 0000000..af0b60e --- /dev/null +++ b/2019/day1/README.md | |||
@@ -0,0 +1,5 @@ | |||
1 | I realized part 1 can be solved with a perl one liner; | ||
2 | |||
3 | ```bash | ||
4 | perl -ne '$c += int ($_ / 3) - 2;END {print $c}' < part1.in | ||
5 | ``` | ||
diff --git a/2019/day1/part1.in b/2019/day1/part1.in new file mode 100644 index 0000000..63d0a1a --- /dev/null +++ b/2019/day1/part1.in | |||
@@ -0,0 +1,100 @@ | |||
1 | 93912 | ||
2 | 138996 | ||
3 | 112824 | ||
4 | 110011 | ||
5 | 139024 | ||
6 | 132292 | ||
7 | 74029 | ||
8 | 81664 | ||
9 | 138077 | ||
10 | 109614 | ||
11 | 121056 | ||
12 | 136338 | ||
13 | 132771 | ||
14 | 86611 | ||
15 | 131526 | ||
16 | 123101 | ||
17 | 61315 | ||
18 | 93900 | ||
19 | 62070 | ||
20 | 97957 | ||
21 | 67168 | ||
22 | 119464 | ||
23 | 119066 | ||
24 | 111076 | ||
25 | 56856 | ||
26 | 144203 | ||
27 | 109400 | ||
28 | 120187 | ||
29 | 57915 | ||
30 | 143353 | ||
31 | 71308 | ||
32 | 67695 | ||
33 | 141275 | ||
34 | 106552 | ||
35 | 136209 | ||
36 | 86990 | ||
37 | 98969 | ||
38 | 57207 | ||
39 | 99103 | ||
40 | 71940 | ||
41 | 63145 | ||
42 | 91765 | ||
43 | 121095 | ||
44 | 139700 | ||
45 | 128851 | ||
46 | 77138 | ||
47 | 66712 | ||
48 | 91318 | ||
49 | 96924 | ||
50 | 132235 | ||
51 | 99897 | ||
52 | 67479 | ||
53 | 87996 | ||
54 | 121100 | ||
55 | 55411 | ||
56 | 61715 | ||
57 | 130658 | ||
58 | 121030 | ||
59 | 141445 | ||
60 | 83939 | ||
61 | 90402 | ||
62 | 121107 | ||
63 | 59618 | ||
64 | 120112 | ||
65 | 58140 | ||
66 | 103514 | ||
67 | 90538 | ||
68 | 55552 | ||
69 | 142739 | ||
70 | 61770 | ||
71 | 147374 | ||
72 | 80038 | ||
73 | 128830 | ||
74 | 93328 | ||
75 | 52369 | ||
76 | 71801 | ||
77 | 144536 | ||
78 | 147140 | ||
79 | 118213 | ||
80 | 128056 | ||
81 | 92155 | ||
82 | 114384 | ||
83 | 89234 | ||
84 | 124451 | ||
85 | 94214 | ||
86 | 79174 | ||
87 | 108427 | ||
88 | 111041 | ||
89 | 96715 | ||
90 | 128414 | ||
91 | 62521 | ||
92 | 93897 | ||
93 | 107428 | ||
94 | 90637 | ||
95 | 126176 | ||
96 | 78676 | ||
97 | 69504 | ||
98 | 93663 | ||
99 | 80869 | ||
100 | 124230 | ||
diff --git a/2019/day1/part2.in b/2019/day1/part2.in new file mode 100644 index 0000000..63d0a1a --- /dev/null +++ b/2019/day1/part2.in | |||
@@ -0,0 +1,100 @@ | |||
1 | 93912 | ||
2 | 138996 | ||
3 | 112824 | ||
4 | 110011 | ||
5 | 139024 | ||
6 | 132292 | ||
7 | 74029 | ||
8 | 81664 | ||
9 | 138077 | ||
10 | 109614 | ||
11 | 121056 | ||
12 | 136338 | ||
13 | 132771 | ||
14 | 86611 | ||
15 | 131526 | ||
16 | 123101 | ||
17 | 61315 | ||
18 | 93900 | ||
19 | 62070 | ||
20 | 97957 | ||
21 | 67168 | ||
22 | 119464 | ||
23 | 119066 | ||
24 | 111076 | ||
25 | 56856 | ||
26 | 144203 | ||
27 | 109400 | ||
28 | 120187 | ||
29 | 57915 | ||
30 | 143353 | ||
31 | 71308 | ||
32 | 67695 | ||
33 | 141275 | ||
34 | 106552 | ||
35 | 136209 | ||
36 | 86990 | ||
37 | 98969 | ||
38 | 57207 | ||
39 | 99103 | ||
40 | 71940 | ||
41 | 63145 | ||
42 | 91765 | ||
43 | 121095 | ||
44 | 139700 | ||
45 | 128851 | ||
46 | 77138 | ||
47 | 66712 | ||
48 | 91318 | ||
49 | 96924 | ||
50 | 132235 | ||
51 | 99897 | ||
52 | 67479 | ||
53 | 87996 | ||
54 | 121100 | ||
55 | 55411 | ||
56 | 61715 | ||
57 | 130658 | ||
58 | 121030 | ||
59 | 141445 | ||
60 | 83939 | ||
61 | 90402 | ||
62 | 121107 | ||
63 | 59618 | ||
64 | 120112 | ||
65 | 58140 | ||
66 | 103514 | ||
67 | 90538 | ||
68 | 55552 | ||
69 | 142739 | ||
70 | 61770 | ||
71 | 147374 | ||
72 | 80038 | ||
73 | 128830 | ||
74 | 93328 | ||
75 | 52369 | ||
76 | 71801 | ||
77 | 144536 | ||
78 | 147140 | ||
79 | 118213 | ||
80 | 128056 | ||
81 | 92155 | ||
82 | 114384 | ||
83 | 89234 | ||
84 | 124451 | ||
85 | 94214 | ||
86 | 79174 | ||
87 | 108427 | ||
88 | 111041 | ||
89 | 96715 | ||
90 | 128414 | ||
91 | 62521 | ||
92 | 93897 | ||
93 | 107428 | ||
94 | 90637 | ||
95 | 126176 | ||
96 | 78676 | ||
97 | 69504 | ||
98 | 93663 | ||
99 | 80869 | ||
100 | 124230 | ||
diff --git a/2019/day1/rec_fuel.py b/2019/day1/rec_fuel.py new file mode 100644 index 0000000..d837202 --- /dev/null +++ b/2019/day1/rec_fuel.py | |||
@@ -0,0 +1,23 @@ | |||
1 | import sys | ||
2 | |||
3 | |||
4 | def recfuel(mass): | ||
5 | """Calculate the fuel required for the module | ||
6 | use the new weight of the fuel recursively | ||
7 | r(M) = r(M / 3 - 2) | ||
8 | """ | ||
9 | M = mass // 3 - 2 | ||
10 | |||
11 | if M < 0: | ||
12 | return 0 | ||
13 | else: | ||
14 | return M + recfuel(M) | ||
15 | |||
16 | |||
17 | total = 0 | ||
18 | |||
19 | for mass in sys.stdin: | ||
20 | ret = recfuel(int(mass)) | ||
21 | total += ret | ||
22 | |||
23 | print(total) | ||
diff --git a/2019/day2/1202.in b/2019/day2/1202.in new file mode 100644 index 0000000..6bbbce6 --- /dev/null +++ b/2019/day2/1202.in | |||
@@ -0,0 +1 @@ | |||
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,1,5,19,23,2,6,23,27,1,27,5,31,2,9,31,35,1,5,35,39,2,6,39,43,2,6,43,47,1,5,47,51,2,9,51,55,1,5,55,59,1,10,59,63,1,63,6,67,1,9,67,71,1,71,6,75,1,75,13,79,2,79,13,83,2,9,83,87,1,87,5,91,1,9,91,95,2,10,95,99,1,5,99,103,1,103,9,107,1,13,107,111,2,111,10,115,1,115,5,119,2,13,119,123,1,9,123,127,1,5,127,131,2,131,6,135,1,135,5,139,1,139,6,143,1,143,6,147,1,2,147,151,1,151,5,0,99,2,14,0,0 | |||
diff --git a/2019/day2/intcode.pl b/2019/day2/intcode.pl new file mode 100644 index 0000000..984784a --- /dev/null +++ b/2019/day2/intcode.pl | |||
@@ -0,0 +1,57 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use Data::Dumper; | ||
4 | # use Smart::Comments; | ||
5 | |||
6 | my $inputline = <STDIN>; | ||
7 | chomp $inputline; | ||
8 | my @memory = split /,/, $inputline; | ||
9 | |||
10 | @memory = map {int $_} @memory; | ||
11 | |||
12 | my $op_code_pos = 0; | ||
13 | my $pos_1 = 1; | ||
14 | my $pos_2 = 2; | ||
15 | my $loc_pos = 3; | ||
16 | my $pc = 4; | ||
17 | |||
18 | my @actions = (sub {print "noop"}, sub {return $_[0] + $_[1]}, sub {return $_[0] * $_[1]}); | ||
19 | |||
20 | my $output = 0; | ||
21 | |||
22 | my $one_inc = 0; | ||
23 | my $two_inc = 0; | ||
24 | my $turn = 0; | ||
25 | my @mem = @memory; | ||
26 | |||
27 | foreach my $x (0..99) { | ||
28 | foreach my $y (0..99) { | ||
29 | |||
30 | @mem = @memory; | ||
31 | $mem[1] = $x; | ||
32 | $mem[2] = $y; | ||
33 | |||
34 | for (my $add = 0; $add < scalar @mem; $add += $pc) { | ||
35 | |||
36 | my $op_code = $mem[$add + $op_code_pos]; | ||
37 | last if ($op_code == 99); | ||
38 | |||
39 | my $op_1 = $mem[$mem[$add + $pos_1]]; | ||
40 | my $op_2 = $mem[$mem[$add + $pos_2]]; | ||
41 | my $loc = $mem[$add + $loc_pos]; | ||
42 | my $res = $actions[$op_code]->($op_1, $op_2); | ||
43 | |||
44 | $mem[$loc] = $res; | ||
45 | } | ||
46 | $output = $mem[0]; | ||
47 | ### $output | ||
48 | exit if $output == 19690720; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | # print Dumper \@mem; | ||
53 | # print join ',', @mem; | ||
54 | END { | ||
55 | print STDERR "Output: >$mem[0]<\nFor mem[1] = $mem[1] and mem[2] = $mem[2]\n"; | ||
56 | print 100 * $mem[1] + $mem[2]; | ||
57 | } | ||
diff --git a/2019/day3/part1.in b/2019/day3/part1.in new file mode 100644 index 0000000..c2e5e1d --- /dev/null +++ b/2019/day3/part1.in | |||
@@ -0,0 +1,2 @@ | |||
1 | R998,U494,L814,D519,R407,U983,R307,D745,R64,D29,L935,D919,L272,D473,R689,U560,L942,U264,R816,U745,R209,U227,R241,U111,L653,D108,R823,U254,L263,U987,L368,D76,R665,D646,L759,U425,L581,D826,R829,D388,L234,U33,L48,U598,L708,D764,L414,D75,L163,U802,L183,U893,L486,U947,L393,D694,L454,D600,R377,U312,R89,D178,L652,D751,R402,D946,R213,U985,R994,D336,R573,D105,L442,U965,R603,U508,L17,U191,L37,U678,L506,U823,R878,D709,L348,U167,L355,U314,L164,D672,L309,U895,R358,D769,R869,U598,R63,D68,R105,U133,R357,U588,L154,D631,L939,D235,R506,D885,R958,D896,L195,U292,L952,D616,L824,D497,R99,D121,R387,D155,L70,U580,L890,D368,L910,U645,L786,U977,R9,U781,L454,U783,L382,U321,L195,U196,L239,U764,R18,D71,R97,U77,L803,U963,L704,U94,L511,U747,L798,D905,L679,D135,R455,U650,R947,U14,L722,D245,L490,D183,L276,U559,L901,D767,R827,U522,L380,U494,R402,U70,R589,D582,R206,U756,L989,U427,L704,D864,R885,D9,R872,U454,R912,U752,R197,U304,L728,U879,R456,D410,L141,U473,R246,U498,R443,D297,R333,D123,R12,D665,R684,D531,R601,D13,L260,U60,R302,D514,R416,D496,L562,D334,L608,U74,R451,U251,R961,U166,L368,U146,R962,U973,R120,U808,R480,D536,L690,D958,R292,U333,R656,U305,R46,U831,L756,D907,L638,D969,L445,U541,R784,U148,R338,D264,R72,D637,R759,D709,L611,D34,R99,U305,R143,D191,R673,D753,R387,U994,R720,D896,R95,U703,L499,D453,R96,U808,L485,U127,L856,U357,L543,U382,R411,U969,L532,U64,R303,U457,L412,D140,R146,D67,R147,D681,L1,D994,L876,D504,R46,U683,L992,U640,L663,D681,L327,U840,R543,U97,R988,U792,R36 | ||
2 | L999,U148,L592,D613,L147,D782,R594,U86,R891,D448,R92,U756,R93,D763,L536,U906,L960,D988,L532,U66,R597,U120,L273,D32,R525,U628,L630,U89,L248,U594,R886,D544,L288,U380,L23,D191,L842,U394,L818,U593,L195,U183,L863,D456,L891,D653,R618,U314,L775,D220,R952,U960,R714,U946,L343,D873,L449,U840,R769,U356,L20,D610,L506,U733,R524,D450,L888,D634,R737,U171,R906,U369,L172,D625,L97,D437,R359,D636,R775,U749,L281,U188,R418,D437,R708,D316,L388,D717,R59,U73,R304,U148,L823,U137,R265,U59,R488,D564,R980,U798,L626,U47,L763,U858,L450,U663,R378,U93,L275,U472,L792,U544,R192,D979,L520,U835,L946,D615,L120,U923,L23,U292,R396,U605,L76,U813,L388,U500,L848,U509,L276,D538,R26,D806,R685,D319,R414,D989,L519,U603,R898,D477,L107,D828,R836,U432,L601,U888,L476,D974,L911,U122,L921,D401,L878,D962,L214,D913,L113,U418,R992,U844,L928,U534,L13,U457,L866,D208,L303,D732,L497,U673,R659,D639,R430,D301,L573,U373,L270,D901,L605,D935,R440,D183,R374,D883,L551,U771,R707,D141,R984,U346,R894,U1,R33,U492,R371,D631,R95,D62,L378,D343,R108,D611,L267,D871,L296,U391,R302,D424,R160,U141,R682,U949,R380,U251,L277,D404,R392,D210,L158,U896,R350,D891,L837,D980,R288,U597,L292,D639,L943,D827,L492,D625,L153,D570,R948,D855,L945,U840,L493,U800,L392,D438,R8,U966,R218,U597,R852,D291,L840,D831,L498,U846,R875,D244,R159,U243,R975,D246,R549,D304,R954,D123,R58,U5,L621,U767,R455,U550,R800,D417,R869,D184,L966,D51,L383,U132,L664,U220,L263,D307,R716,U346,L958,U84,L154,U90,L726,U628,L159,U791,L643,D652,L138,U577,R457,U655,L547,D441,L21 | ||
diff --git a/2019/day3/smalltest.in b/2019/day3/smalltest.in new file mode 100644 index 0000000..620a05e --- /dev/null +++ b/2019/day3/smalltest.in | |||
@@ -0,0 +1,2 @@ | |||
1 | R75,D30,R83,U83,L12,D49,R71,U7,L72 | ||
2 | U62,R66,U55,R34,D71,R55,D58,R83 | ||
diff --git a/2019/day3/wires.pl b/2019/day3/wires.pl new file mode 100644 index 0000000..fa4ddf1 --- /dev/null +++ b/2019/day3/wires.pl | |||
@@ -0,0 +1,68 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | use strict; | ||
3 | use warnings; | ||
4 | |||
5 | use List::Util 'min'; | ||
6 | # use Smart::Comments; | ||
7 | use Data::Dumper; | ||
8 | |||
9 | sub manhattan_distance { | ||
10 | my $ref = shift; | ||
11 | my ($x, $y) = @{$ref}; | ||
12 | |||
13 | return abs(0 - $x) + abs(0 - $y); | ||
14 | } | ||
15 | |||
16 | sub pedometer { | ||
17 | my $ref = shift; | ||
18 | my ($x, $y, $step_1, $step_2) = @{$ref}; | ||
19 | return $step_1 + $step_2; | ||
20 | } | ||
21 | |||
22 | my %directions = ( | ||
23 | 'U' => [0, 1], | ||
24 | 'D' => [0,-1], | ||
25 | 'R' => [1, 0], | ||
26 | 'L' => [-1,0] | ||
27 | ); | ||
28 | |||
29 | my $turn = 0; | ||
30 | my @intersections = (); | ||
31 | my %map; | ||
32 | |||
33 | while(<>) { | ||
34 | chomp; | ||
35 | my @path = split /,/; | ||
36 | my @coord = (0,0); # Starting point | ||
37 | my $num_steps = 0; | ||
38 | |||
39 | if (!$turn){ | ||
40 | foreach my $way (@path) { | ||
41 | my ($dir, $speed) = ($1, $2) if ($way =~ /(\w)(\d+)/) or die "$!"; | ||
42 | for (1..$speed) { | ||
43 | $coord[0] += @{$directions{$dir}}[0]; | ||
44 | $coord[1] += @{$directions{$dir}}[1]; | ||
45 | $num_steps++; | ||
46 | $map{"$coord[0],$coord[1]"} = $num_steps; | ||
47 | } | ||
48 | } | ||
49 | $turn = !$turn; | ||
50 | } else { | ||
51 | foreach my $way (@path) { | ||
52 | my ($dir, $speed) = ($1, $2) if ($way =~ /(\w)(\d+)/) or die "$!"; | ||
53 | for (1..$speed) { | ||
54 | $coord[0] += @{$directions{$dir}}[0]; | ||
55 | $coord[1] += @{$directions{$dir}}[1]; | ||
56 | $num_steps++; | ||
57 | if (exists $map{"$coord[0],$coord[1]"}) { | ||
58 | push @intersections, [@coord,$num_steps,$map{"$coord[0],$coord[1]"}]; | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | # print Dumper \@intersections; | ||
66 | print(min(map {pedometer($_);} @intersections)); | ||
67 | |||
68 | |||
diff --git a/2019/day4/password.lp b/2019/day4/password.lp new file mode 100644 index 0000000..b9a1f1a --- /dev/null +++ b/2019/day4/password.lp | |||
@@ -0,0 +1,17 @@ | |||
1 | %353096-843212 | ||
2 | digit(X) :- X = 0..9. | ||
3 | place(N) :- N = 1..6. | ||
4 | |||
5 | 1 {pass(Q,X) : digit(X)} 1 :- place(Q). | ||
6 | value(N) :- N = A + B * 10 + C * 100 + D * 1000 + E * 10000 + F * 100000, pass(6,A), pass(5,B), pass(4,C), pass(3,D), pass(2,E), pass(1,F). | ||
7 | |||
8 | :- value(N), N < 353096. | ||
9 | :- value(N), N > 843212. | ||
10 | |||
11 | :- pass(Q,X), pass(Q', Y), Q' = Q + 1, X > Y. | ||
12 | %:- pass(Q,X), pass(Q', Y), pass(QQ, Z), Q' = Q + 1, QQ = Q' + 1, X = Y, Y = Z. % I couldn't figure out this so I did 581 - 2 | ||
13 | |||
14 | %1 {target(X,Y,XX,YY) : dir(DX,DY), XX-X = DX*S, YY-Y = DY*S, size(S), area(XX,YY,_)} 1 :- number(X,Y,_). | ||
15 | |||
16 | #show pass/2. | ||
17 | #show value/1. | ||
diff --git a/2019/day4/password.pl b/2019/day4/password.pl new file mode 100644 index 0000000..403cf91 --- /dev/null +++ b/2019/day4/password.pl | |||
@@ -0,0 +1,29 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | |||
4 | use Data::Dumper; | ||
5 | |||
6 | my $low_bound = 353096; | ||
7 | my $upper_bound = 843212; | ||
8 | |||
9 | my $count = 0; | ||
10 | |||
11 | for (my $number = $low_bound; $number < $upper_bound; $number++) { | ||
12 | my @nums = split //, $number; | ||
13 | my @cmp = sort {$a <=> $b} @nums; | ||
14 | if (@nums == @cmp and join ("\0", @nums) eq join ("\0", @cmp)) { | ||
15 | my %digits = (); | ||
16 | foreach (@nums) { | ||
17 | $digits{$_}++; | ||
18 | } | ||
19 | foreach my $reps (values %digits) { | ||
20 | if ($reps == 2) { | ||
21 | print "$number\n"; | ||
22 | $count++; | ||
23 | last; | ||
24 | } | ||
25 | } | ||
26 | } | ||
27 | } | ||
28 | |||
29 | print ">$count\n"; | ||
diff --git a/2019/day5/intcode.pl b/2019/day5/intcode.pl new file mode 100644 index 0000000..613f067 --- /dev/null +++ b/2019/day5/intcode.pl | |||
@@ -0,0 +1,92 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use Data::Dumper; | ||
4 | # use Smart::Comments; | ||
5 | use v5.10; | ||
6 | |||
7 | sub pos { | ||
8 | my ($tape_ref, $index) = @_; | ||
9 | my @tape = @{ $tape_ref }; | ||
10 | ### returning: $tape[$tape[$index]] | ||
11 | ### for: $index | ||
12 | return $tape[$tape[$index]]; | ||
13 | } | ||
14 | |||
15 | sub imm { | ||
16 | my ($tape_ref, $index) = @_; | ||
17 | my @tape = @{ $tape_ref }; | ||
18 | return $tape[$index]; | ||
19 | } | ||
20 | |||
21 | my $inputline = <STDIN>; | ||
22 | chomp $inputline; | ||
23 | my @tape = split /,/, $inputline; | ||
24 | |||
25 | my $pc = 0; # program counter is no longer consistent | ||
26 | |||
27 | my @actions = ( | ||
28 | sub { print "noop" }, # no opcode 0 | ||
29 | sub { return $_[0] + $_[1] }, # 1 | ||
30 | sub { return $_[0] * $_[1] }, # 2 | ||
31 | sub { return 5; }, # 3 | ||
32 | sub { say $_[0]; }, # 4 | ||
33 | sub { return $_[0] ? $_[1] : -1 }, # 5, ugh, you might want to jump to 0 | ||
34 | sub { return $_[0] ? -1 : $_[1] }, # 6 | ||
35 | sub { return $_[0] < $_[1] ? 1 : 0}, # 7 | ||
36 | sub { return $_[0] == $_[1] ? 1 : 0}, # 8 | ||
37 | ); | ||
38 | |||
39 | my @modes = (\&pos, \&imm); | ||
40 | my %offsets = qw/1 4 2 4 3 2 4 2 5 3 6 3 7 4 8 4 99 1/; | ||
41 | my $inst_ptr = 0; | ||
42 | |||
43 | while ( 1 ) { | ||
44 | |||
45 | my $raw_op_code = $tape[$inst_ptr]; | ||
46 | last if ($raw_op_code == 99); | ||
47 | |||
48 | # print("====================================\n"); | ||
49 | |||
50 | my @modes_and_opcode; | ||
51 | push @modes_and_opcode, $_ // 0 for $raw_op_code =~ m/^(\d)??(\d)??(\d)??0?(\d)$/g; | ||
52 | ### @modes_and_opcode | ||
53 | |||
54 | my $op_code = pop @modes_and_opcode; | ||
55 | ### $op_code | ||
56 | |||
57 | # foreach my $x (0..5) { | ||
58 | # print("TAPE[" . ($inst_ptr + $x) . "] = $tape[($inst_ptr + $x)]\n") | ||
59 | # } | ||
60 | |||
61 | my $toread = $offsets{$op_code} - 1; # excluding opcode | ||
62 | my @params; | ||
63 | foreach my $offset (1..$toread) { | ||
64 | push @params, $modes[ (!($op_code == 4 || $op_code == 5 || $op_code == 6) && $offset == $toread) ? 1 : pop @modes_and_opcode ]->(\@tape, $inst_ptr + $offset); | ||
65 | } | ||
66 | ### @params | ||
67 | |||
68 | $inst_ptr += $offsets{$op_code}; | ||
69 | |||
70 | if ($op_code == 1 || $op_code == 2 || $op_code == 7 || $op_code == 8) { # arithmetic | ||
71 | my $res = $actions[$op_code]->($params[0], $params[1]); | ||
72 | $tape[$params[2]] = $res; | ||
73 | ### writing: $res | ||
74 | ### on address: $params[2] | ||
75 | } | ||
76 | elsif ($op_code == 3) { # input | ||
77 | my $res = $actions[$op_code]->(); | ||
78 | $tape[$params[0]] = $res; | ||
79 | ### saved: $res | ||
80 | ### on: $params[0] | ||
81 | } elsif ($op_code == 4) { # output | ||
82 | $actions[$op_code]->($params[0]); | ||
83 | } elsif ($op_code == 5 || $op_code == 6) { # jumps | ||
84 | my $res = $actions[$op_code]->($params[0], $params[1]); | ||
85 | $inst_ptr = $res == -1 ? $inst_ptr : $res; | ||
86 | ### jumped to: $inst_ptr | ||
87 | next; | ||
88 | } else { | ||
89 | ### OH NO... | ||
90 | die; | ||
91 | } | ||
92 | } | ||
diff --git a/2019/day5/part1.in b/2019/day5/part1.in new file mode 100644 index 0000000..9d9b84d --- /dev/null +++ b/2019/day5/part1.in | |||
@@ -0,0 +1 @@ | |||
3,225,1,225,6,6,1100,1,238,225,104,0,1002,114,19,224,1001,224,-646,224,4,224,102,8,223,223,1001,224,7,224,1,223,224,223,1101,40,62,225,1101,60,38,225,1101,30,29,225,2,195,148,224,1001,224,-40,224,4,224,1002,223,8,223,101,2,224,224,1,224,223,223,1001,143,40,224,101,-125,224,224,4,224,1002,223,8,223,1001,224,3,224,1,224,223,223,101,29,139,224,1001,224,-99,224,4,224,1002,223,8,223,1001,224,2,224,1,224,223,223,1101,14,34,225,102,57,39,224,101,-3420,224,224,4,224,102,8,223,223,1001,224,7,224,1,223,224,223,1101,70,40,225,1102,85,69,225,1102,94,5,225,1,36,43,224,101,-92,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1102,94,24,224,1001,224,-2256,224,4,224,102,8,223,223,1001,224,1,224,1,223,224,223,1102,8,13,225,1101,36,65,224,1001,224,-101,224,4,224,102,8,223,223,101,3,224,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,8,677,226,224,1002,223,2,223,1006,224,329,1001,223,1,223,1108,226,226,224,1002,223,2,223,1005,224,344,101,1,223,223,1108,226,677,224,1002,223,2,223,1006,224,359,101,1,223,223,107,226,226,224,1002,223,2,223,1005,224,374,101,1,223,223,1107,226,226,224,1002,223,2,223,1005,224,389,101,1,223,223,107,677,677,224,102,2,223,223,1006,224,404,101,1,223,223,1008,226,226,224,1002,223,2,223,1006,224,419,101,1,223,223,108,677,226,224,1002,223,2,223,1006,224,434,101,1,223,223,1108,677,226,224,102,2,223,223,1005,224,449,101,1,223,223,1008,677,226,224,102,2,223,223,1006,224,464,1001,223,1,223,108,677,677,224,102,2,223,223,1005,224,479,101,1,223,223,7,677,677,224,102,2,223,223,1005,224,494,1001,223,1,223,8,226,677,224,102,2,223,223,1006,224,509,101,1,223,223,107,677,226,224,1002,223,2,223,1005,224,524,1001,223,1,223,7,677,226,224,1002,223,2,223,1005,224,539,1001,223,1,223,1007,226,677,224,1002,223,2,223,1005,224,554,1001,223,1,223,8,677,677,224,102,2,223,223,1006,224,569,101,1,223,223,7,226,677,224,102,2,223,223,1006,224,584,1001,223,1,223,1008,677,677,224,102,2,223,223,1005,224,599,101,1,223,223,1007,677,677,224,1002,223,2,223,1006,224,614,101,1,223,223,1107,677,226,224,1002,223,2,223,1006,224,629,101,1,223,223,1107,226,677,224,1002,223,2,223,1006,224,644,101,1,223,223,1007,226,226,224,102,2,223,223,1005,224,659,1001,223,1,223,108,226,226,224,102,2,223,223,1006,224,674,101,1,223,223,4,223,99,226 | |||
diff --git a/2019/day6/orbits.pl b/2019/day6/orbits.pl new file mode 100644 index 0000000..9f4aed5 --- /dev/null +++ b/2019/day6/orbits.pl | |||
@@ -0,0 +1,39 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | |||
4 | my $file_name = $ARGV[0]; | ||
5 | |||
6 | if (not defined $file_name) { | ||
7 | die "missing filename\n"; | ||
8 | } | ||
9 | |||
10 | open my $fh, "<", $file_name or die "Can't open $file_name, $!\n"; | ||
11 | |||
12 | my %orbit; | ||
13 | |||
14 | while (<$fh>) { | ||
15 | chomp; | ||
16 | my ($from, $to) = split /\)/; | ||
17 | push @{ $orbit{$from} }, $to; | ||
18 | } | ||
19 | |||
20 | close $fh; | ||
21 | |||
22 | my @to_value = ('---', 'COM'); | ||
23 | my $dist = 0; | ||
24 | my $total = 0; | ||
25 | |||
26 | while ( 1 ) { | ||
27 | |||
28 | my $cur = pop @to_value; | ||
29 | |||
30 | print $total and exit unless @to_value; | ||
31 | |||
32 | if ($cur eq '---') { | ||
33 | unshift @to_value, '---'; | ||
34 | $dist++; | ||
35 | } else { | ||
36 | $total += $dist; | ||
37 | unshift @to_value, @{ $orbit{$cur} } if exists $orbit{$cur}; | ||
38 | } | ||
39 | } | ||
diff --git a/2019/day6/orbits.py b/2019/day6/orbits.py new file mode 100644 index 0000000..652256f --- /dev/null +++ b/2019/day6/orbits.py | |||
@@ -0,0 +1,28 @@ | |||
1 | # this solves part 2 | ||
2 | import sys | ||
3 | |||
4 | import networkx as nx | ||
5 | |||
6 | |||
7 | def main(argv): | ||
8 | |||
9 | G = nx.DiGraph() | ||
10 | with open(argv[0]) as fp: | ||
11 | for line in fp: | ||
12 | line = line.rstrip("\n") | ||
13 | start, end = line.split(")") | ||
14 | G.add_node(start, label=start) | ||
15 | G.add_node(end, label=end) | ||
16 | G.add_edge(start, end) | ||
17 | |||
18 | jump_to = nx.lowest_common_ancestor(G, "SAN", "YOU") # SAN and YOU are given | ||
19 | jumps = ( | ||
20 | len(nx.shortest_path(G, jump_to, "SAN")) | ||
21 | + len(nx.shortest_path(G, jump_to, "YOU")) | ||
22 | - 4 | ||
23 | ) # 4 because len includes start and end, so -2 times 2 | ||
24 | print(jumps) | ||
25 | |||
26 | |||
27 | if __name__ == "__main__": | ||
28 | main(sys.argv[1:]) | ||
diff --git a/2019/day6/part1.in b/2019/day6/part1.in new file mode 100644 index 0000000..8cafbd0 --- /dev/null +++ b/2019/day6/part1.in | |||
@@ -0,0 +1,1069 @@ | |||
1 | WGB)S14 | ||
2 | WN4)27C | ||
3 | 18L)M18 | ||
4 | 1HY)6ZP | ||
5 | TQ9)KQ6 | ||
6 | HQ3)HH1 | ||
7 | FLC)F1Z | ||
8 | D6R)ZPC | ||
9 | 2VD)GK3 | ||
10 | YY3)3TP | ||
11 | PBL)3CK | ||
12 | 5K4)CB5 | ||
13 | V5M)CNN | ||
14 | L4T)RHS | ||
15 | HHH)66F | ||
16 | Q3Y)DTL | ||
17 | DGN)YY3 | ||
18 | CCT)L3B | ||
19 | Z6X)FM2 | ||
20 | 2QQ)VK9 | ||
21 | MX3)C9J | ||
22 | 4JK)BPX | ||
23 | 8BP)N13 | ||
24 | PBW)6Z6 | ||
25 | 2LT)DT9 | ||
26 | JHX)GXM | ||
27 | 5LW)BHQ | ||
28 | DNK)ZBT | ||
29 | 29Z)T9D | ||
30 | WNP)TDC | ||
31 | S38)GL6 | ||
32 | DW9)V2F | ||
33 | 4MG)3FW | ||
34 | Z9Z)CPK | ||
35 | FKL)QNH | ||
36 | 55D)HT2 | ||
37 | D1D)N4Q | ||
38 | Y7W)1Y8 | ||
39 | SFQ)79W | ||
40 | JSR)62W | ||
41 | 4WN)J18 | ||
42 | VK9)J2H | ||
43 | LS5)DCX | ||
44 | 6LR)P4X | ||
45 | HDV)DGQ | ||
46 | 1K9)KD1 | ||
47 | 2PX)17C | ||
48 | KSB)GL8 | ||
49 | B4S)VTV | ||
50 | ZW1)KNR | ||
51 | BVH)43P | ||
52 | VKP)6L3 | ||
53 | P5K)MHR | ||
54 | XHR)STT | ||
55 | WBG)5X5 | ||
56 | HZF)8JQ | ||
57 | B47)NW4 | ||
58 | J5V)3ZW | ||
59 | KGP)VVR | ||
60 | 24K)PK8 | ||
61 | 31V)LXC | ||
62 | 5XG)RHP | ||
63 | P1G)HN8 | ||
64 | R76)3GY | ||
65 | 5CH)17Q | ||
66 | TVC)XJM | ||
67 | 598)RD3 | ||
68 | J66)LKC | ||
69 | 4DY)YSQ | ||
70 | M4Y)NLL | ||
71 | SMP)M2M | ||
72 | TBR)WNP | ||
73 | K22)KGP | ||
74 | MQ5)8MN | ||
75 | B9Q)6HQ | ||
76 | P9S)X92 | ||
77 | TJK)ZQK | ||
78 | XS7)7KL | ||
79 | H6J)DX1 | ||
80 | MTP)3Z6 | ||
81 | B17)B7P | ||
82 | S12)PC2 | ||
83 | 47V)5KW | ||
84 | KCY)HWP | ||
85 | FB2)S38 | ||
86 | V5M)FNT | ||
87 | GXM)QPR | ||
88 | HXR)2R2 | ||
89 | 2LV)NDP | ||
90 | 6HQ)12S | ||
91 | 22P)4HL | ||
92 | T8Q)9FB | ||
93 | 8YW)TVZ | ||
94 | DR1)NNN | ||
95 | 9TH)87Z | ||
96 | 79W)TM2 | ||
97 | 5GB)HQM | ||
98 | 1HY)4WN | ||
99 | LFV)RYJ | ||
100 | YCN)ZMK | ||
101 | 8SR)SB3 | ||
102 | P9H)PH9 | ||
103 | ZGQ)T3J | ||
104 | KWW)1HY | ||
105 | TLF)RPG | ||
106 | PFD)HZR | ||
107 | 9SF)7PY | ||
108 | DCX)VCC | ||
109 | D1R)2RB | ||
110 | GXC)NN9 | ||
111 | ZZW)SCC | ||
112 | G44)Q8D | ||
113 | 923)3J2 | ||
114 | KY2)8F4 | ||
115 | 1XQ)7LD | ||
116 | GHX)Q6M | ||
117 | TZ5)V32 | ||
118 | LM9)1XK | ||
119 | Q7N)Z7H | ||
120 | YKD)73H | ||
121 | 9RZ)C2Q | ||
122 | 5KN)P1G | ||
123 | 3FJ)L73 | ||
124 | ZPC)VYT | ||
125 | Y7D)FFY | ||
126 | C8W)J1Y | ||
127 | X5T)55D | ||
128 | Z3F)GK8 | ||
129 | WRS)PRR | ||
130 | T9M)JK2 | ||
131 | 81P)5WT | ||
132 | 7KL)5BK | ||
133 | S3R)VCD | ||
134 | 56L)D1R | ||
135 | PR2)92L | ||
136 | 91F)2F4 | ||
137 | ND4)PJ6 | ||
138 | 9KY)YD4 | ||
139 | CLH)5D7 | ||
140 | J2F)L7Z | ||
141 | M4Y)PYG | ||
142 | 891)P34 | ||
143 | VV6)18L | ||
144 | RQQ)X8P | ||
145 | 7SR)8G6 | ||
146 | WJ8)CDL | ||
147 | 9FB)TXD | ||
148 | RKK)2H5 | ||
149 | 3W8)2QQ | ||
150 | 27C)YFC | ||
151 | RZZ)91F | ||
152 | 4CP)BWH | ||
153 | T4L)LS5 | ||
154 | 788)G7S | ||
155 | 47V)3W8 | ||
156 | FGK)719 | ||
157 | 16Q)4KW | ||
158 | 5H6)PC9 | ||
159 | KGS)TBR | ||
160 | 44Y)BVH | ||
161 | GMF)VFM | ||
162 | LKC)PM4 | ||
163 | DPL)DXS | ||
164 | 2WD)X5T | ||
165 | XWX)NYR | ||
166 | N44)Y36 | ||
167 | 72S)56L | ||
168 | W25)4MG | ||
169 | P9S)HBC | ||
170 | W84)3YP | ||
171 | NW4)S78 | ||
172 | 58Y)LDB | ||
173 | QJ9)VV1 | ||
174 | 5D3)4Q7 | ||
175 | T3J)5M4 | ||
176 | 394)ZW7 | ||
177 | JXL)QVK | ||
178 | 7KL)FTL | ||
179 | 885)ZGQ | ||
180 | 58Y)8SR | ||
181 | GXN)PBW | ||
182 | HH1)JB4 | ||
183 | H6J)W95 | ||
184 | VYK)SQS | ||
185 | CCS)7CZ | ||
186 | PJ7)NLR | ||
187 | 2VW)MSP | ||
188 | ZWK)H6X | ||
189 | HJ4)C1S | ||
190 | H41)1L3 | ||
191 | 8B9)64N | ||
192 | RZR)WBJ | ||
193 | FNT)VL7 | ||
194 | K5M)S5Q | ||
195 | XJM)TC7 | ||
196 | QWT)7Q5 | ||
197 | 43P)MY2 | ||
198 | YP7)51N | ||
199 | TDX)FWZ | ||
200 | DB3)NCK | ||
201 | 37M)H2L | ||
202 | Z3X)XRS | ||
203 | SGV)R2T | ||
204 | Y2F)63M | ||
205 | ZVY)JTX | ||
206 | DJB)KQD | ||
207 | 848)FQP | ||
208 | SX3)FM5 | ||
209 | PH9)ZPG | ||
210 | 75S)Z9L | ||
211 | GPD)Y7D | ||
212 | 9Y6)52N | ||
213 | SL4)S3R | ||
214 | 4TH)T6F | ||
215 | K4V)D8V | ||
216 | 89S)18F | ||
217 | GDN)WN4 | ||
218 | 6HT)TQZ | ||
219 | V1Q)JVG | ||
220 | R55)2LC | ||
221 | KH3)NT5 | ||
222 | Q53)3DN | ||
223 | SRV)JND | ||
224 | XMC)MKK | ||
225 | T5J)6HT | ||
226 | HZR)M1M | ||
227 | P34)3RY | ||
228 | HF6)SD2 | ||
229 | PTM)C9X | ||
230 | 3MZ)T9M | ||
231 | R76)MFF | ||
232 | B9Y)3MC | ||
233 | NFG)5FC | ||
234 | M63)4CP | ||
235 | FRG)PVQ | ||
236 | 58Z)GDM | ||
237 | ZT8)4L5 | ||
238 | F5B)KF3 | ||
239 | SQT)NTZ | ||
240 | M2M)252 | ||
241 | 35Y)5WF | ||
242 | C9J)8BP | ||
243 | W8H)F78 | ||
244 | H8Z)2VW | ||
245 | 91P)5FP | ||
246 | VTV)YN7 | ||
247 | 2KM)1K9 | ||
248 | KSX)TR8 | ||
249 | 9DK)XD6 | ||
250 | MFF)KQR | ||
251 | 414)6L9 | ||
252 | FQ7)T5K | ||
253 | G8M)WPX | ||
254 | 794)FMS | ||
255 | WZV)XS7 | ||
256 | VVR)5CH | ||
257 | R8G)9RH | ||
258 | B4D)2RT | ||
259 | PJ6)GWB | ||
260 | 63M)NHF | ||
261 | 8G7)8B9 | ||
262 | QP5)9ZW | ||
263 | FW6)CDM | ||
264 | S5Q)172 | ||
265 | T24)TPD | ||
266 | YRT)GMF | ||
267 | 1TJ)SGV | ||
268 | RV3)C3D | ||
269 | 661)MHS | ||
270 | QYT)D2K | ||
271 | T49)MFP | ||
272 | GY7)T2Q | ||
273 | 686)Z4G | ||
274 | J49)R9L | ||
275 | R5S)67X | ||
276 | L7Z)5RM | ||
277 | RPP)WG9 | ||
278 | 5KW)2KM | ||
279 | 5N2)Y7W | ||
280 | Z3X)JFD | ||
281 | KD8)4H5 | ||
282 | 5MP)RVK | ||
283 | 12S)S2Y | ||
284 | TPD)D5F | ||
285 | 51N)81P | ||
286 | DCH)SGQ | ||
287 | L6N)VKP | ||
288 | 2XQ)6LR | ||
289 | 3DN)S3L | ||
290 | VS4)83N | ||
291 | 8DJ)WZP | ||
292 | DCX)FX1 | ||
293 | SF9)Z3F | ||
294 | R49)S99 | ||
295 | D1C)794 | ||
296 | TKN)L83 | ||
297 | 21R)GP3 | ||
298 | 5RM)TG3 | ||
299 | ZMK)R49 | ||
300 | 1QT)152 | ||
301 | 9DX)GXC | ||
302 | GYC)TQ9 | ||
303 | JND)LMK | ||
304 | D8Z)SCW | ||
305 | VNZ)VS4 | ||
306 | C1S)9RZ | ||
307 | LKF)D8Z | ||
308 | G4J)R44 | ||
309 | 92L)J66 | ||
310 | 88P)657 | ||
311 | 8Z5)R55 | ||
312 | VV1)KRY | ||
313 | N44)2QK | ||
314 | KBC)KKG | ||
315 | 91P)L6N | ||
316 | SVH)7W3 | ||
317 | P9Z)34H | ||
318 | BWH)9TH | ||
319 | JNX)RZZ | ||
320 | YFG)ZT8 | ||
321 | DSM)FF3 | ||
322 | BMK)ZR6 | ||
323 | 7W3)V82 | ||
324 | T9D)H2S | ||
325 | 2QF)PFD | ||
326 | NDQ)F13 | ||
327 | ZVB)MX6 | ||
328 | KRY)7FB | ||
329 | KKG)HJ4 | ||
330 | QNH)MFQ | ||
331 | 5X5)VQM | ||
332 | HQM)HF6 | ||
333 | HLT)TD2 | ||
334 | WV4)FWH | ||
335 | N2T)5B5 | ||
336 | D1R)P89 | ||
337 | HKT)3MZ | ||
338 | ZQK)1DK | ||
339 | QQQ)FLC | ||
340 | 73Z)TTM | ||
341 | ZZW)769 | ||
342 | 8G7)TYL | ||
343 | MFP)WMS | ||
344 | RQS)2YC | ||
345 | NLL)JHX | ||
346 | KCY)CSP | ||
347 | 9F8)51H | ||
348 | SGQ)B27 | ||
349 | 4KM)VYK | ||
350 | JDY)MTW | ||
351 | T8Q)DB3 | ||
352 | 1VL)VV6 | ||
353 | VV5)B4D | ||
354 | SPF)JR5 | ||
355 | LYS)6CK | ||
356 | YMK)2VD | ||
357 | TD2)1VL | ||
358 | JKH)QHX | ||
359 | VD4)58J | ||
360 | 9QQ)HKL | ||
361 | 8JP)HQ3 | ||
362 | NHS)31S | ||
363 | 81Z)Q5W | ||
364 | R7Q)Z9M | ||
365 | WMS)ZK2 | ||
366 | 3J2)GY7 | ||
367 | MFQ)CLH | ||
368 | S14)934 | ||
369 | HY7)YBT | ||
370 | 4SY)63F | ||
371 | NQF)PPQ | ||
372 | T9W)RZR | ||
373 | WL2)6QM | ||
374 | LZV)WRQ | ||
375 | TVZ)T9P | ||
376 | 4X5)GN5 | ||
377 | NQ8)FPQ | ||
378 | J5J)K51 | ||
379 | Y8T)WGM | ||
380 | FPQ)B53 | ||
381 | 1XK)TKX | ||
382 | XDW)72V | ||
383 | WW8)9QQ | ||
384 | XX7)Q7N | ||
385 | CDM)GHX | ||
386 | VCC)HPP | ||
387 | QRK)56B | ||
388 | MTW)2QT | ||
389 | 7V5)58Z | ||
390 | PYY)T24 | ||
391 | 9HB)J8F | ||
392 | TTM)PTB | ||
393 | FF3)ZY3 | ||
394 | ZW7)D1D | ||
395 | T4H)ZTG | ||
396 | 2PW)DSM | ||
397 | 9WB)4TH | ||
398 | 17C)FKX | ||
399 | T6F)QP3 | ||
400 | G6R)XHR | ||
401 | H5T)QYT | ||
402 | DX1)Q9L | ||
403 | GJF)ZF3 | ||
404 | LJP)JXL | ||
405 | QHX)3XY | ||
406 | DNF)8KQ | ||
407 | 8Q1)NDQ | ||
408 | GP3)6MY | ||
409 | FPQ)QQQ | ||
410 | XRS)923 | ||
411 | Q6M)7BS | ||
412 | K21)B47 | ||
413 | TQZ)WJ4 | ||
414 | 9PB)3PQ | ||
415 | 8G6)X7M | ||
416 | L3B)YOU | ||
417 | L5V)G2L | ||
418 | B8Y)JVS | ||
419 | GL6)MTP | ||
420 | 9QZ)NRN | ||
421 | 486)T8Q | ||
422 | HNN)PNM | ||
423 | NFK)B4S | ||
424 | G9C)LHT | ||
425 | 4K9)SL4 | ||
426 | 8X5)179 | ||
427 | VQM)47V | ||
428 | CNJ)J4R | ||
429 | ZD5)2PX | ||
430 | 9TQ)X9Q | ||
431 | Q3Q)9DK | ||
432 | 17Q)1KX | ||
433 | 5GN)24K | ||
434 | K5Q)1NF | ||
435 | LCK)9WB | ||
436 | TYL)PYL | ||
437 | 7XG)R2L | ||
438 | LXC)ZWK | ||
439 | Q62)SPF | ||
440 | 89C)N7Z | ||
441 | GK8)GR7 | ||
442 | 6X1)5N2 | ||
443 | XM8)8Q1 | ||
444 | MCD)GXQ | ||
445 | S2Y)N7G | ||
446 | CB5)C8W | ||
447 | NHF)44B | ||
448 | QPR)GF5 | ||
449 | HGX)YMY | ||
450 | 3FW)2LV | ||
451 | 5WF)RQQ | ||
452 | 841)N31 | ||
453 | Q9L)876 | ||
454 | WQ8)HZ7 | ||
455 | 6K1)QVC | ||
456 | C2T)FQX | ||
457 | J3M)HLT | ||
458 | H2S)K5Q | ||
459 | STQ)8ZF | ||
460 | VDX)NQF | ||
461 | YSR)G8M | ||
462 | CSL)NLF | ||
463 | MHS)3FH | ||
464 | YN7)VWC | ||
465 | RSW)X11 | ||
466 | FXS)L54 | ||
467 | YBT)HX4 | ||
468 | BHQ)FRG | ||
469 | 83H)K4Q | ||
470 | NT5)2ZB | ||
471 | GWB)4K9 | ||
472 | YMY)5KN | ||
473 | 4Q7)C3G | ||
474 | D3J)HZF | ||
475 | 32D)GN7 | ||
476 | VGG)G3D | ||
477 | LVG)JXR | ||
478 | 25V)GDN | ||
479 | L6V)KL8 | ||
480 | FW2)STQ | ||
481 | V6H)8G7 | ||
482 | COM)CB6 | ||
483 | 6Z6)SQT | ||
484 | W81)6M3 | ||
485 | D2K)XF6 | ||
486 | 2NX)9KY | ||
487 | KRQ)LKF | ||
488 | P1B)VVQ | ||
489 | QTV)Q3Y | ||
490 | DTZ)ZLY | ||
491 | R3T)FQ7 | ||
492 | D92)72S | ||
493 | H8N)9Y6 | ||
494 | FWZ)WGB | ||
495 | VQW)LHJ | ||
496 | 2HB)848 | ||
497 | 9ZW)NT8 | ||
498 | NLR)QTV | ||
499 | 31V)DSZ | ||
500 | 92J)WXY | ||
501 | 8LK)QQ3 | ||
502 | 769)ZD5 | ||
503 | 8L9)T5J | ||
504 | TB2)V5M | ||
505 | VZQ)57T | ||
506 | Z7H)JMR | ||
507 | 94D)YCN | ||
508 | ZPF)6WK | ||
509 | M1F)6C2 | ||
510 | MHV)ZCS | ||
511 | Q53)FBC | ||
512 | RPG)P3N | ||
513 | RHS)JDY | ||
514 | FTL)FB2 | ||
515 | J47)R3T | ||
516 | Y9S)4JK | ||
517 | ZVY)TK6 | ||
518 | LTX)BM5 | ||
519 | D8V)3R6 | ||
520 | J18)S19 | ||
521 | PVQ)WL2 | ||
522 | ZPV)QFW | ||
523 | 719)CSV | ||
524 | XK9)9Q9 | ||
525 | BM5)L5V | ||
526 | LDF)WZT | ||
527 | MSP)DTZ | ||
528 | HRQ)JBG | ||
529 | 19C)GSP | ||
530 | GPB)HGX | ||
531 | 2F4)8HL | ||
532 | 886)C8J | ||
533 | ZF3)LM9 | ||
534 | NQ1)394 | ||
535 | WM9)M79 | ||
536 | PM4)GNT | ||
537 | 6J4)ML2 | ||
538 | 5WT)HQS | ||
539 | KQD)5K4 | ||
540 | JBT)V1Q | ||
541 | JVS)DDT | ||
542 | 3G2)52L | ||
543 | 8ZF)D6R | ||
544 | 4BQ)5H6 | ||
545 | G7T)7T6 | ||
546 | ZY3)83H | ||
547 | HYC)G9C | ||
548 | MX6)XC9 | ||
549 | 2NW)2SH | ||
550 | YXJ)JSR | ||
551 | QNH)YJN | ||
552 | TG3)886 | ||
553 | N7Z)G98 | ||
554 | 5D7)KNW | ||
555 | 8TN)KH3 | ||
556 | C78)TSW | ||
557 | 87Z)DFM | ||
558 | QGG)Q53 | ||
559 | NRN)YP7 | ||
560 | TTB)C2T | ||
561 | ZLY)25P | ||
562 | 7KS)D5X | ||
563 | LNX)CNJ | ||
564 | QVK)YMK | ||
565 | CNN)N43 | ||
566 | 5Q9)MWG | ||
567 | SCC)XFV | ||
568 | 885)G7T | ||
569 | 4BS)4BQ | ||
570 | N4Q)Z6X | ||
571 | FQX)7W4 | ||
572 | MLL)NF8 | ||
573 | 52N)PZ2 | ||
574 | DNF)KBC | ||
575 | 6C2)CCS | ||
576 | LZ8)P1B | ||
577 | CSV)686 | ||
578 | PZ2)KKC | ||
579 | JMR)327 | ||
580 | 3TP)N6L | ||
581 | 3W8)YFG | ||
582 | S62)J5V | ||
583 | FF3)VXL | ||
584 | 4X4)MHQ | ||
585 | 3TP)7Z7 | ||
586 | L83)VDN | ||
587 | Q8D)2HB | ||
588 | JB4)5LR | ||
589 | VYT)SAN | ||
590 | L54)X63 | ||
591 | 15J)XF2 | ||
592 | FWZ)WLR | ||
593 | R44)K5M | ||
594 | TK6)Q5J | ||
595 | J81)QP5 | ||
596 | 114)BGP | ||
597 | QQ3)PJ7 | ||
598 | D5F)HNN | ||
599 | MFF)WW8 | ||
600 | J18)MP3 | ||
601 | 9JN)M8G | ||
602 | 2YC)CSL | ||
603 | R2T)4TS | ||
604 | ZBT)WQ8 | ||
605 | XFV)MPD | ||
606 | R9S)XDW | ||
607 | 8HL)99X | ||
608 | 4MG)2QF | ||
609 | 8X5)BMK | ||
610 | CN7)KSB | ||
611 | YJN)44Y | ||
612 | X11)WWY | ||
613 | 5MP)VDX | ||
614 | R2L)PFY | ||
615 | 6ZP)HPW | ||
616 | WGM)GPB | ||
617 | WCZ)KCY | ||
618 | NYR)TKN | ||
619 | 1L3)SKC | ||
620 | MND)S5K | ||
621 | 17N)2D1 | ||
622 | VL7)16Q | ||
623 | 5FP)J5J | ||
624 | NBL)TLF | ||
625 | QDV)Z9Z | ||
626 | 2S1)VXW | ||
627 | K22)G6R | ||
628 | DTL)9Z8 | ||
629 | BXN)YXJ | ||
630 | VYW)LNX | ||
631 | WJ4)4LM | ||
632 | JTX)DPL | ||
633 | SLM)DNF | ||
634 | YM4)J37 | ||
635 | 4L5)BF4 | ||
636 | 2RT)8DD | ||
637 | FNB)KD8 | ||
638 | PK8)9PD | ||
639 | RLR)4SY | ||
640 | TM2)661 | ||
641 | PQ6)2FF | ||
642 | 92J)XMC | ||
643 | GDM)21R | ||
644 | ZTG)VV5 | ||
645 | X3B)ZZW | ||
646 | 5XQ)H6J | ||
647 | WTL)W1N | ||
648 | PNM)H8Z | ||
649 | 6MY)CG5 | ||
650 | 72V)RLR | ||
651 | 3R6)WCZ | ||
652 | PF8)YRM | ||
653 | HPY)88T | ||
654 | X8P)MHN | ||
655 | 7LY)6VJ | ||
656 | 2FF)C9G | ||
657 | K4Q)4BS | ||
658 | X63)2WD | ||
659 | XM8)R8Q | ||
660 | G98)Z3X | ||
661 | 44B)8DJ | ||
662 | PWZ)V1P | ||
663 | MDD)7ZX | ||
664 | RRD)T49 | ||
665 | YBJ)DBX | ||
666 | GXQ)BXP | ||
667 | 6FX)88P | ||
668 | WXZ)H22 | ||
669 | 18F)WTL | ||
670 | NQF)885 | ||
671 | L4T)XM2 | ||
672 | V82)4DY | ||
673 | 6N6)TDX | ||
674 | 172)QRK | ||
675 | N6L)23T | ||
676 | CSP)5MP | ||
677 | GLG)9TQ | ||
678 | 9P6)R76 | ||
679 | W1N)N3F | ||
680 | R8G)JZ1 | ||
681 | H2L)F2D | ||
682 | TGT)C9S | ||
683 | 7BS)2XQ | ||
684 | FWH)TVM | ||
685 | 23T)K3L | ||
686 | WQX)37M | ||
687 | 3ZW)QH7 | ||
688 | BGP)FW6 | ||
689 | YFC)FGH | ||
690 | JCF)94D | ||
691 | WRQ)9JN | ||
692 | GN5)6RM | ||
693 | V6H)QGG | ||
694 | C1S)XK9 | ||
695 | FFY)9SF | ||
696 | WPX)HKT | ||
697 | 7Y1)NBL | ||
698 | 6RN)GPD | ||
699 | NYJ)YDT | ||
700 | 934)FKL | ||
701 | P3N)FXS | ||
702 | ZQS)KXC | ||
703 | 4KW)PVJ | ||
704 | FMS)V26 | ||
705 | NT8)WM9 | ||
706 | 7Z7)G4J | ||
707 | NN9)2TT | ||
708 | VXW)DJB | ||
709 | C97)Q3Q | ||
710 | VVQ)486 | ||
711 | CB6)DGN | ||
712 | DGQ)WMN | ||
713 | FM5)GJF | ||
714 | 6YY)DPN | ||
715 | DDT)814 | ||
716 | KF3)SFQ | ||
717 | G7S)TTB | ||
718 | R4C)S12 | ||
719 | R8Q)35Y | ||
720 | GXN)JKH | ||
721 | J2H)K22 | ||
722 | F5B)7LY | ||
723 | NCK)YSR | ||
724 | SMP)KY2 | ||
725 | P4X)X3B | ||
726 | DR5)LZ8 | ||
727 | 8JQ)ZPV | ||
728 | WG9)SX3 | ||
729 | NDQ)LM2 | ||
730 | 32S)LFV | ||
731 | K51)ND4 | ||
732 | DP3)QDV | ||
733 | 2W7)CCT | ||
734 | RSK)YH6 | ||
735 | 9NZ)NSB | ||
736 | K3L)RV3 | ||
737 | HN8)414 | ||
738 | 92N)75S | ||
739 | 61M)598 | ||
740 | ZR6)53T | ||
741 | J8F)TB2 | ||
742 | H22)5YX | ||
743 | HSJ)M63 | ||
744 | 4KW)5GB | ||
745 | HR7)89C | ||
746 | FQP)15J | ||
747 | TZ5)LYS | ||
748 | 5FP)WG4 | ||
749 | 4HL)PBL | ||
750 | C8J)D1C | ||
751 | TS3)83C | ||
752 | C3G)1QT | ||
753 | GZD)DNK | ||
754 | 2RB)KSF | ||
755 | BCD)SF9 | ||
756 | 327)9QZ | ||
757 | 4FF)ZQS | ||
758 | 6L9)82F | ||
759 | TJK)123 | ||
760 | X9M)FMY | ||
761 | R92)TV1 | ||
762 | CDL)2PW | ||
763 | 7ZX)58Y | ||
764 | C2N)H5T | ||
765 | 8MN)TH2 | ||
766 | GN7)G44 | ||
767 | HKL)61M | ||
768 | XD6)1C9 | ||
769 | ZCS)NQ8 | ||
770 | 2L8)QGH | ||
771 | DFC)XX7 | ||
772 | S5K)XM8 | ||
773 | 58J)8L9 | ||
774 | PRR)4KM | ||
775 | 6XT)N2T | ||
776 | FM2)7Y1 | ||
777 | V26)HR7 | ||
778 | 2TT)91P | ||
779 | 88F)ZW1 | ||
780 | JBG)891 | ||
781 | WZT)VZQ | ||
782 | PYG)NHS | ||
783 | 2QT)P9H | ||
784 | FB2)9QT | ||
785 | MP3)PQ6 | ||
786 | WZV)YBJ | ||
787 | H53)VYW | ||
788 | N2T)VQW | ||
789 | ZK2)6RT | ||
790 | SQS)5XQ | ||
791 | DPN)W8H | ||
792 | TSW)2L8 | ||
793 | 73H)R7Q | ||
794 | F1Z)B9Q | ||
795 | M8G)9KS | ||
796 | NSB)H41 | ||
797 | WBJ)THR | ||
798 | KSF)KGS | ||
799 | PXH)3BS | ||
800 | 4NT)ZRV | ||
801 | VNZ)8X5 | ||
802 | 98S)DR1 | ||
803 | 3XY)TJK | ||
804 | JNX)P9Z | ||
805 | F4P)6YY | ||
806 | VRT)VKV | ||
807 | TVM)92N | ||
808 | WLR)S62 | ||
809 | D5X)ZVB | ||
810 | 152)9P6 | ||
811 | F2D)PN3 | ||
812 | 2R2)D6K | ||
813 | ZRV)2NX | ||
814 | 67X)TS3 | ||
815 | HWP)YBD | ||
816 | 5FC)SRV | ||
817 | X92)CQR | ||
818 | 8N9)DFC | ||
819 | Q5J)H8N | ||
820 | GGG)8LK | ||
821 | PPQ)841 | ||
822 | 6RT)WJ8 | ||
823 | KQR)788 | ||
824 | 92N)Q62 | ||
825 | W7S)98S | ||
826 | S19)NFK | ||
827 | VRM)ZVY | ||
828 | GL8)DCH | ||
829 | 4YM)17N | ||
830 | F13)D3J | ||
831 | QVC)VGG | ||
832 | 31S)J81 | ||
833 | 934)93X | ||
834 | Q21)R4C | ||
835 | TH2)HQ4 | ||
836 | 1C9)114 | ||
837 | 83N)X5B | ||
838 | S3L)T4L | ||
839 | SD2)ZWX | ||
840 | SC1)6K1 | ||
841 | TXD)ZPF | ||
842 | 3GY)NQ1 | ||
843 | Z9M)9NS | ||
844 | D6R)7V5 | ||
845 | WG4)C2N | ||
846 | SVH)JBT | ||
847 | TR8)K4V | ||
848 | MPD)7SR | ||
849 | Y36)DP3 | ||
850 | LM2)K21 | ||
851 | KD1)2S1 | ||
852 | FC8)J3M | ||
853 | JFD)BWF | ||
854 | 6Y3)88F | ||
855 | STT)GXN | ||
856 | KKC)DW9 | ||
857 | 52L)B3G | ||
858 | 5BK)XWX | ||
859 | H6X)5BQ | ||
860 | YH6)FGK | ||
861 | VM3)6RN | ||
862 | BWH)1PZ | ||
863 | JK2)BCD | ||
864 | 9QT)LTX | ||
865 | 6WK)F5B | ||
866 | HYC)C97 | ||
867 | GSP)3MR | ||
868 | 6M3)B9P | ||
869 | 7LD)9NZ | ||
870 | N31)7KS | ||
871 | GGG)9PB | ||
872 | 6RM)SC1 | ||
873 | 83C)TGT | ||
874 | BWT)1TJ | ||
875 | 7YH)CN7 | ||
876 | JLD)PFT | ||
877 | W95)JNX | ||
878 | ZBT)Y2F | ||
879 | TPD)RSK | ||
880 | 3BS)BR6 | ||
881 | KG9)X9M | ||
882 | 6HL)5D3 | ||
883 | WMN)P9S | ||
884 | V32)V6H | ||
885 | RYJ)3HM | ||
886 | SF9)SBK | ||
887 | HQ4)19C | ||
888 | BWF)2W7 | ||
889 | 2LC)91R | ||
890 | VCD)3G2 | ||
891 | VKJ)9BJ | ||
892 | NL2)VKJ | ||
893 | NLF)HY7 | ||
894 | BR6)L6V | ||
895 | TQ4)8N9 | ||
896 | QH7)W84 | ||
897 | D6K)GGG | ||
898 | W1J)SLM | ||
899 | DB2)RQS | ||
900 | M18)RRD | ||
901 | DXS)32S | ||
902 | KL8)YRT | ||
903 | Q5W)VD4 | ||
904 | SCC)WQX | ||
905 | GQW)VRT | ||
906 | 52N)J47 | ||
907 | Z9M)6FX | ||
908 | FKX)GSK | ||
909 | TKX)WRS | ||
910 | 7YH)NFG | ||
911 | 9Y6)WZV | ||
912 | 7BS)48W | ||
913 | NT5)KSX | ||
914 | 1Y8)RYV | ||
915 | 814)J2F | ||
916 | GSK)KRQ | ||
917 | FBC)W1J | ||
918 | C9G)VRY | ||
919 | V2F)8TN | ||
920 | 5M4)Y9S | ||
921 | X9Q)T71 | ||
922 | Q7G)9HB | ||
923 | YLR)4YM | ||
924 | 18L)29D | ||
925 | M1M)1BT | ||
926 | 82F)MX3 | ||
927 | 9BJ)BBL | ||
928 | R55)HRQ | ||
929 | 9RH)R5S | ||
930 | 414)MHV | ||
931 | ML2)Y8T | ||
932 | 179)7YH | ||
933 | GK3)5Q9 | ||
934 | 7CZ)VRM | ||
935 | QP3)LDF | ||
936 | YRM)D92 | ||
937 | KXC)B8Y | ||
938 | 2ZB)6X1 | ||
939 | XWX)JCF | ||
940 | B3G)CG7 | ||
941 | LHT)4NT | ||
942 | NNN)5LW | ||
943 | 48W)R9S | ||
944 | 91R)6J4 | ||
945 | 97T)BBF | ||
946 | 1BT)KWW | ||
947 | B53)QL9 | ||
948 | HBC)DB2 | ||
949 | 2D1)89S | ||
950 | BBL)WBG | ||
951 | 7WK)LJP | ||
952 | TV1)SNJ | ||
953 | K5Q)L9Q | ||
954 | HNN)YKD | ||
955 | BXP)W81 | ||
956 | 64N)GLG | ||
957 | L9Q)M4Y | ||
958 | PTB)8JP | ||
959 | RHP)3FJ | ||
960 | 657)PWZ | ||
961 | HZ7)T8S | ||
962 | YKD)W25 | ||
963 | PYL)SMP | ||
964 | YSQ)HSJ | ||
965 | W84)9F8 | ||
966 | HQS)NL2 | ||
967 | 3MC)6Y3 | ||
968 | 24K)MDD | ||
969 | G3D)B17 | ||
970 | 2QF)PXH | ||
971 | 38D)FNB | ||
972 | 614)SVH | ||
973 | 34H)BWT | ||
974 | 6L3)GZD | ||
975 | J1Y)QJ9 | ||
976 | 3XF)GG9 | ||
977 | MHQ)25V | ||
978 | 3PQ)L4T | ||
979 | 57T)3W4 | ||
980 | 8KQ)614 | ||
981 | PC9)P5K | ||
982 | C2Q)F4P | ||
983 | J37)FW2 | ||
984 | TDC)M1F | ||
985 | YD4)LZV | ||
986 | 4H5)HYC | ||
987 | VRY)5XG | ||
988 | 3W4)YLR | ||
989 | JZ1)Q21 | ||
990 | SBK)1XQ | ||
991 | RVK)6XT | ||
992 | 9NS)LVG | ||
993 | JBT)612 | ||
994 | J4R)QWT | ||
995 | YDT)31V | ||
996 | 123)C78 | ||
997 | PN3)PTM | ||
998 | 6QM)5GN | ||
999 | CG7)PF8 | ||
1000 | HX4)T4H | ||
1001 | 6CK)HXR | ||
1002 | PFT)H53 | ||
1003 | 62W)FC8 | ||
1004 | KQ6)4X5 | ||
1005 | 3CK)8Z5 | ||
1006 | RHS)Q7G | ||
1007 | N13)2LT | ||
1008 | D3J)NYJ | ||
1009 | PFY)N44 | ||
1010 | N3F)4FF | ||
1011 | P89)29Z | ||
1012 | MHN)J49 | ||
1013 | S78)LCK | ||
1014 | 8DD)DR5 | ||
1015 | 51H)VM3 | ||
1016 | 1NF)MLL | ||
1017 | S99)RKK | ||
1018 | 9PD)JLD | ||
1019 | 7Q5)7WK | ||
1020 | 7WK)MND | ||
1021 | CQR)KG9 | ||
1022 | X5B)VTN | ||
1023 | SCW)RPP | ||
1024 | BF4)3XF | ||
1025 | QL9)R8G | ||
1026 | LDB)4X4 | ||
1027 | VDN)73Z | ||
1028 | 9KY)BXN | ||
1029 | VTN)WJ1 | ||
1030 | 8F4)PR2 | ||
1031 | F78)92J | ||
1032 | 7SX)GQW | ||
1033 | GR7)22P | ||
1034 | 56B)7SX | ||
1035 | 876)HPY | ||
1036 | HNP)V7Y | ||
1037 | SNJ)HHH | ||
1038 | KNR)W7S | ||
1039 | HT2)T9W | ||
1040 | PC2)B9Y | ||
1041 | 6VJ)HNP | ||
1042 | 4TS)32D | ||
1043 | 7FB)TZ5 | ||
1044 | 5BQ)PRT | ||
1045 | PRT)97T | ||
1046 | G44)9DX | ||
1047 | THR)81Z | ||
1048 | 25P)MCD | ||
1049 | Z9L)R92 | ||
1050 | V1P)L1D | ||
1051 | DSZ)TVC | ||
1052 | VKV)TQ4 | ||
1053 | 4LM)YM4 | ||
1054 | T8S)6N6 | ||
1055 | HPP)WV4 | ||
1056 | 99X)8YW | ||
1057 | B9P)HDV | ||
1058 | T2Q)TNM | ||
1059 | JVG)7XG | ||
1060 | QGH)KTD | ||
1061 | DBX)VNZ | ||
1062 | DFM)RSW | ||
1063 | 29D)GYC | ||
1064 | LYS)38D | ||
1065 | MKK)WXZ | ||
1066 | 5B5)MQ5 | ||
1067 | BPX)2NW | ||
1068 | 5LR)PYY | ||
1069 | VXL)6HL | ||
diff --git a/2019/day7/comm.py b/2019/day7/comm.py new file mode 100644 index 0000000..458d8b1 --- /dev/null +++ b/2019/day7/comm.py | |||
@@ -0,0 +1,19 @@ | |||
1 | from itertools import permutations | ||
2 | import os | ||
3 | import subprocess | ||
4 | |||
5 | perm = permutations(range(5)) | ||
6 | res = [] | ||
7 | |||
8 | for seq in perm: | ||
9 | signal = 0 | ||
10 | for phase in seq: | ||
11 | out = subprocess.run( | ||
12 | ["perl", "intcode.pl", "part1.in"], | ||
13 | capture_output=True, | ||
14 | input=b"%d\n%d" % (phase, signal), | ||
15 | ) | ||
16 | signal = int(out.stdout) | ||
17 | res.append(signal) | ||
18 | |||
19 | print(sorted(res)[-1]) | ||
diff --git a/2019/day7/intcode.pl b/2019/day7/intcode.pl new file mode 100644 index 0000000..d83d2db --- /dev/null +++ b/2019/day7/intcode.pl | |||
@@ -0,0 +1,109 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use Data::Dumper; | ||
4 | # use Smart::Comments; | ||
5 | use v5.10; | ||
6 | |||
7 | $| = 1; | ||
8 | |||
9 | sub pos { | ||
10 | my ($tape_ref, $index) = @_; | ||
11 | my @tape = @{ $tape_ref }; | ||
12 | ### returning: $tape[$tape[$index]] | ||
13 | ### for: $index | ||
14 | return $tape[$tape[$index]]; | ||
15 | } | ||
16 | |||
17 | sub imm { | ||
18 | my ($tape_ref, $index) = @_; | ||
19 | my @tape = @{ $tape_ref }; | ||
20 | return $tape[$index]; | ||
21 | } | ||
22 | |||
23 | my $file_name = $ARGV[0]; | ||
24 | |||
25 | if (not defined $file_name) { | ||
26 | die "missing filename\n"; | ||
27 | } | ||
28 | |||
29 | open my $fh, "<", $file_name or die "Can't open $file_name, $!\n"; | ||
30 | |||
31 | my $inputline = <$fh>; | ||
32 | chomp $inputline; | ||
33 | my @tape = split /,/, $inputline; | ||
34 | close $fh; | ||
35 | |||
36 | my $pc = 0; # program counter is no longer consistent | ||
37 | |||
38 | my @actions = ( | ||
39 | sub { print "noop" }, # no opcode 0 | ||
40 | sub { return $_[0] + $_[1] }, # 1 | ||
41 | sub { return $_[0] * $_[1] }, # 2 | ||
42 | sub { | ||
43 | print STDERR ("Getting input!\n"); | ||
44 | my $in = <STDIN>; | ||
45 | print STDERR ("Read >$in<\n"); | ||
46 | chomp $in; | ||
47 | return $in; | ||
48 | }, # 3 | ||
49 | sub { say $_[0]; }, # 4 | ||
50 | sub { return $_[0] ? $_[1] : -1 }, # 5, ugh, you might want to jump to 0 | ||
51 | sub { return $_[0] ? -1 : $_[1] }, # 6 | ||
52 | sub { return $_[0] < $_[1] ? 1 : 0}, # 7 | ||
53 | sub { return $_[0] == $_[1] ? 1 : 0}, # 8 | ||
54 | ); | ||
55 | |||
56 | my @modes = (\&pos, \&imm); | ||
57 | my %offsets = qw/1 4 2 4 3 2 4 2 5 3 6 3 7 4 8 4 99 1/; | ||
58 | my $inst_ptr = 0; | ||
59 | |||
60 | while ( 1 ) { | ||
61 | |||
62 | my $raw_op_code = $tape[$inst_ptr]; | ||
63 | last if ($raw_op_code == 99); | ||
64 | |||
65 | # print("====================================\n"); | ||
66 | |||
67 | my @modes_and_opcode; | ||
68 | push @modes_and_opcode, $_ // 0 for $raw_op_code =~ m/^(\d)??(\d)??(\d)??0?(\d)$/g; | ||
69 | ### @modes_and_opcode | ||
70 | |||
71 | my $op_code = pop @modes_and_opcode; | ||
72 | ### $op_code | ||
73 | |||
74 | # foreach my $x (0..5) { | ||
75 | # print("TAPE[" . ($inst_ptr + $x) . "] = $tape[($inst_ptr + $x)]\n") | ||
76 | # } | ||
77 | |||
78 | my $toread = $offsets{$op_code} - 1; # excluding opcode | ||
79 | my @params; | ||
80 | foreach my $offset (1..$toread) { | ||
81 | push @params, $modes[ (!($op_code == 4 || $op_code == 5 || $op_code == 6) && $offset == $toread) ? 1 : pop @modes_and_opcode ]->(\@tape, $inst_ptr + $offset); | ||
82 | } | ||
83 | ### @params | ||
84 | |||
85 | $inst_ptr += $offsets{$op_code}; | ||
86 | |||
87 | if ($op_code == 1 || $op_code == 2 || $op_code == 7 || $op_code == 8) { # arithmetic | ||
88 | my $res = $actions[$op_code]->($params[0], $params[1]); | ||
89 | $tape[$params[2]] = $res; | ||
90 | ### writing: $res | ||
91 | ### on address: $params[2] | ||
92 | } | ||
93 | elsif ($op_code == 3) { # input | ||
94 | my $res = $actions[$op_code]->(); | ||
95 | $tape[$params[0]] = $res; | ||
96 | ### saved: $res | ||
97 | ### on: $params[0] | ||
98 | } elsif ($op_code == 4) { # output | ||
99 | $actions[$op_code]->($params[0]); | ||
100 | } elsif ($op_code == 5 || $op_code == 6) { # jumps | ||
101 | my $res = $actions[$op_code]->($params[0], $params[1]); | ||
102 | $inst_ptr = $res == -1 ? $inst_ptr : $res; | ||
103 | ### jumped to: $inst_ptr | ||
104 | next; | ||
105 | } else { | ||
106 | ### OH NO... | ||
107 | die; | ||
108 | } | ||
109 | } | ||
diff --git a/2019/day7/part1.in b/2019/day7/part1.in new file mode 100644 index 0000000..a700dd4 --- /dev/null +++ b/2019/day7/part1.in | |||
@@ -0,0 +1 @@ | |||
3,8,1001,8,10,8,105,1,0,0,21,46,59,72,93,110,191,272,353,434,99999,3,9,101,4,9,9,1002,9,3,9,1001,9,5,9,102,2,9,9,1001,9,5,9,4,9,99,3,9,1002,9,5,9,1001,9,5,9,4,9,99,3,9,101,4,9,9,1002,9,4,9,4,9,99,3,9,102,3,9,9,101,3,9,9,1002,9,2,9,1001,9,5,9,4,9,99,3,9,1001,9,2,9,102,4,9,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,99 | |||