From: Jan "Yenya" Kasprzak Date: Fri, 13 Dec 2024 12:09:40 +0000 (+0100) Subject: Day 13: linear equations X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=a86def06881eee1c93b637479cf4f5378ea090a5;p=aoc.git Day 13: linear equations --- diff --git a/2024/25.pl b/2024/25.pl new file mode 100755 index 0000000..be0ca50 --- /dev/null +++ b/2024/25.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl -w + +use v5.40; + +my $cost; +while (1) { + my ($ax, $ay) = <> =~/\d+/g; + my ($bx, $by) = <> =~/\d+/g; + my ($px, $py) = <> =~/\d+/g; + + for my $na (1 .. 100) { + last if $ax * $na > $px; + last if $ay * $na > $py; + next if ($px - $ax * $na) % $bx; + next if ($py - $ay * $na) % $by; + next if ($px - $ax * $na) / $bx != ($py - $ay * $na) / $by; + my $c = $na*3 + ($px - $ax * $na) / $bx; + $cost += $c; + + last; + } + last if !defined <>; +} + +say $cost; diff --git a/2024/26.pl b/2024/26.pl new file mode 100755 index 0000000..4b6b4a3 --- /dev/null +++ b/2024/26.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w + +use v5.40; + +my $cost; +while (1) { + my ($ax, $ay) = <> =~/\d+/g; + my ($bx, $by) = <> =~/\d+/g; + my ($px, $py) = <> =~/\d+/g; + $px += 10000000000000; + $py += 10000000000000; + + my $nb = ($px*$ay - $py*$ax) / ($bx*$ay - $ax*$by); + my $na = ($px - $nb*$bx) / $ax; + + $cost += 3*$na+$nb + if $na == int($na) && $nb == int($nb); + + last if !defined <>; +} +say $cost;