From 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 12 Dec 2021 01:24:32 +0300 Subject: 2020, tracking --- 2020/day10/input | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2020/day10/joltage.pl | 29 ++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 2020/day10/input create mode 100644 2020/day10/joltage.pl (limited to '2020/day10') 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 @@ +26 +97 +31 +7 +2 +10 +46 +38 +112 +54 +30 +93 +18 +111 +29 +75 +139 +23 +132 +85 +78 +99 +8 +113 +87 +57 +133 +41 +104 +98 +58 +90 +13 +91 +20 +68 +103 +127 +105 +114 +138 +126 +67 +32 +145 +115 +16 +141 +1 +73 +45 +119 +51 +40 +35 +150 +118 +53 +80 +79 +65 +135 +74 +47 +128 +64 +17 +4 +84 +83 +147 +142 +146 +9 +125 +94 +140 +131 +134 +92 +66 +122 +19 +86 +50 +52 +108 +100 +71 +61 +44 +39 +3 +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 @@ +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]" -- cgit v1.2.3-70-g09d2