diff options
author | Yigit Sever | 2021-12-13 10:38:11 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-13 10:38:11 +0300 |
commit | 74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch) | |
tree | e27db4cd0873c81a53d32277446d926d176304e0 /2020/day10 | |
parent | 3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff) | |
parent | ac8125750abed263619da4cc6d653bb5ab76f007 (diff) | |
download | aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2 aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day10')
-rw-r--r-- | 2020/day10/input | 94 | ||||
-rw-r--r-- | 2020/day10/joltage.pl | 29 |
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 @@ | |||
1 | 26 | ||
2 | 97 | ||
3 | 31 | ||
4 | 7 | ||
5 | 2 | ||
6 | 10 | ||
7 | 46 | ||
8 | 38 | ||
9 | 112 | ||
10 | 54 | ||
11 | 30 | ||
12 | 93 | ||
13 | 18 | ||
14 | 111 | ||
15 | 29 | ||
16 | 75 | ||
17 | 139 | ||
18 | 23 | ||
19 | 132 | ||
20 | 85 | ||
21 | 78 | ||
22 | 99 | ||
23 | 8 | ||
24 | 113 | ||
25 | 87 | ||
26 | 57 | ||
27 | 133 | ||
28 | 41 | ||
29 | 104 | ||
30 | 98 | ||
31 | 58 | ||
32 | 90 | ||
33 | 13 | ||
34 | 91 | ||
35 | 20 | ||
36 | 68 | ||
37 | 103 | ||
38 | 127 | ||
39 | 105 | ||
40 | 114 | ||
41 | 138 | ||
42 | 126 | ||
43 | 67 | ||
44 | 32 | ||
45 | 145 | ||
46 | 115 | ||
47 | 16 | ||
48 | 141 | ||
49 | 1 | ||
50 | 73 | ||
51 | 45 | ||
52 | 119 | ||
53 | 51 | ||
54 | 40 | ||
55 | 35 | ||
56 | 150 | ||
57 | 118 | ||
58 | 53 | ||
59 | 80 | ||
60 | 79 | ||
61 | 65 | ||
62 | 135 | ||
63 | 74 | ||
64 | 47 | ||
65 | 128 | ||
66 | 64 | ||
67 | 17 | ||
68 | 4 | ||
69 | 84 | ||
70 | 83 | ||
71 | 147 | ||
72 | 142 | ||
73 | 146 | ||
74 | 9 | ||
75 | 125 | ||
76 | 94 | ||
77 | 140 | ||
78 | 131 | ||
79 | 134 | ||
80 | 92 | ||
81 | 66 | ||
82 | 122 | ||
83 | 19 | ||
84 | 86 | ||
85 | 50 | ||
86 | 52 | ||
87 | 108 | ||
88 | 100 | ||
89 | 71 | ||
90 | 61 | ||
91 | 44 | ||
92 | 39 | ||
93 | 3 | ||
94 | 72 | ||
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 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use DDP; | ||
4 | use Smart::Comments; | ||
5 | use List::Util qw(sum min); | ||
6 | |||
7 | my @jolts = sort { $a <=> $b } map { int } <>; | ||
8 | |||
9 | @jolts = (0, @jolts, $jolts[-1] + 3); | ||
10 | |||
11 | my %diffs; | ||
12 | |||
13 | my $curr = 0; | ||
14 | |||
15 | foreach my $joltage (@jolts) { | ||
16 | $diffs{$joltage - $curr}++; | ||
17 | $curr = $joltage; | ||
18 | } | ||
19 | |||
20 | p %diffs; | ||
21 | |||
22 | print($diffs{1} * $diffs{3}); | ||
23 | |||
24 | my @memoi = (1); | ||
25 | for my $k (1..$#jolts) { | ||
26 | push @memoi, sum map {$memoi[$k-$_]} grep {$jolts[$k-$_]+3 >= $jolts[$k]} 1..min($k,3); | ||
27 | } | ||
28 | |||
29 | print "\n$memoi[-1]" | ||