summaryrefslogtreecommitdiffstats
path: root/2020/day10/joltage.pl
blob: 3a220578b1dce03d9803c6423866ed04c9145f16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use strict;
use warnings;
use DDP;
use Smart::Comments;
use List::Util qw(sum min);

my @jolts = sort { $a <=> $b } map { int } <>;

@jolts = (0, @jolts, $jolts[-1] + 3);

my %diffs;

my $curr = 0;

foreach my $joltage (@jolts) {
    $diffs{$joltage - $curr}++;
    $curr = $joltage;
}

p %diffs;

print($diffs{1} * $diffs{3});

my @memoi = (1);
for my $k (1..$#jolts) {
    push @memoi, sum map {$memoi[$k-$_]} grep {$jolts[$k-$_]+3 >= $jolts[$k]} 1..min($k,3);
}

print "\n$memoi[-1]"