From: Jan "Yenya" Kasprzak Date: Mon, 4 Dec 2023 07:31:26 +0000 (+0100) Subject: Day 4: not bad, but too slow X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc.git;a=commitdiff_plain;h=37802cc99a47b0fb10fd37fe7886f3d812b0d989 Day 4: not bad, but too slow --- diff --git a/2023/07.pl b/2023/07.pl new file mode 100755 index 0000000..eb32805 --- /dev/null +++ b/2023/07.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl -w + +use v5.38; + +my $sum; +while (<>) { + my ($have, $win) = /: (.*) \| (.*)/; + my %is_win = map { $_ => 1 } ($win =~ /(\d+)/g); + my $count = grep { $is_win{$_} } ($have =~ /(\d+)/g); + $sum += 1 << ($count-1) if $count; +} +say $sum; diff --git a/2023/08.pl b/2023/08.pl new file mode 100755 index 0000000..3c558e5 --- /dev/null +++ b/2023/08.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl -w + +use v5.38; + +my $sum; +my @scores; +while (<>) { + my ($have, $win) = /: (.*) \| (.*)/; + my %is_win = map { $_ => 1 } ($win =~ /(\d+)/g); + push @scores, scalar grep { $is_win{$_} } ($have =~ /(\d+)/g); +} + +my @cards = (1) x @scores; +while (@scores) { + my $n = shift @scores; + my $c = shift @cards; + $sum += $c; + next if !$n; + $cards[$_] += $c for 0 .. $n-1; +} + +say $sum;