summaryrefslogtreecommitdiffstats
path: root/2020/day10
diff options
context:
space:
mode:
authorYigit Sever2021-12-12 01:24:32 +0300
committerYigit Sever2021-12-12 01:24:32 +0300
commit4bb6f8d06c0e384f3394012b1d48da58ed28cc5e (patch)
treed6478c85c0488a1059567ccd2882cb10039c2546 /2020/day10
parentae3853b6e8ab02023ccd74baac6dc177b1ee879a (diff)
downloadaoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.gz
aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.bz2
aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.zip
2020, tracking
Diffstat (limited to '2020/day10')
-rw-r--r--2020/day10/input94
-rw-r--r--2020/day10/joltage.pl29
2 files changed, 123 insertions, 0 deletions
diff --git a/2020/day10/input b/2020/day10/input
new file mode 100644
index 0000000..8d69912
--- /dev/null
+++ b/2020/day10/input
@@ -0,0 +1,94 @@
126
297
331
47
52
610
746
838
9112
1054
1130
1293
1318
14111
1529
1675
17139
1823
19132
2085
2178
2299
238
24113
2587
2657
27133
2841
29104
3098
3158
3290
3313
3491
3520
3668
37103
38127
39105
40114
41138
42126
4367
4432
45145
46115
4716
48141
491
5073
5145
52119
5351
5440
5535
56150
57118
5853
5980
6079
6165
62135
6374
6447
65128
6664
6717
684
6984
7083
71147
72142
73146
749
75125
7694
77140
78131
79134
8092
8166
82122
8319
8486
8550
8652
87108
88100
8971
9061
9144
9239
933
9472
diff --git a/2020/day10/joltage.pl b/2020/day10/joltage.pl
new file mode 100644
index 0000000..3a22057
--- /dev/null
+++ b/2020/day10/joltage.pl
@@ -0,0 +1,29 @@
1use strict;
2use warnings;
3use DDP;
4use Smart::Comments;
5use List::Util qw(sum min);
6
7my @jolts = sort { $a <=> $b } map { int } <>;
8
9@jolts = (0, @jolts, $jolts[-1] + 3);
10
11my %diffs;
12
13my $curr = 0;
14
15foreach my $joltage (@jolts) {
16 $diffs{$joltage - $curr}++;
17 $curr = $joltage;
18}
19
20p %diffs;
21
22print($diffs{1} * $diffs{3});
23
24my @memoi = (1);
25for my $k (1..$#jolts) {
26 push @memoi, sum map {$memoi[$k-$_]} grep {$jolts[$k-$_]+3 >= $jolts[$k]} 1..min($k,3);
27}
28
29print "\n$memoi[-1]"