From: Jan "Yenya" Kasprzak Date: Sun, 1 Dec 2024 05:54:35 +0000 (+0100) Subject: 2024 Day 1: need to read the task more carefully X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=735c1cc915c215e9d9e47c3e4c470ef4abb7326e;p=aoc.git 2024 Day 1: need to read the task more carefully --- diff --git a/2024/01.pl b/2024/01.pl new file mode 100755 index 0000000..aeb93cc --- /dev/null +++ b/2024/01.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +use v5.40; + +my (@l1, @l2); +while (<>) { + my @f = /\d+/g; + push @l1, $f[0]; + push @l2, $f[1]; +} +@l1 = sort { $a <=> $b } @l1; +@l2 = sort { $a <=> $b } @l2; + +my $sum; +while (@l1) { + $sum += abs(shift(@l1) - shift(@l2)); +} + +say $sum; + diff --git a/2024/02.pl b/2024/02.pl new file mode 100755 index 0000000..99f0018 --- /dev/null +++ b/2024/02.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl -w + +use v5.40; + +my (@l, %h); +while (<>) { + my @f = /\d+/g; + push @l, $f[0]; + $h{$f[1]}++; +} + +my $sum; +$sum += $_ * $h{$_} for @l; + +say $sum; +