From 37802cc99a47b0fb10fd37fe7886f3d812b0d989 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Mon, 4 Dec 2023 08:31:26 +0100 Subject: [PATCH] Day 4: not bad, but too slow --- 2023/07.pl | 12 ++++++++++++ 2023/08.pl | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 2023/07.pl create mode 100755 2023/08.pl 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; -- 2.43.5