From 3c294a0ce3522e0392eaaae5dd38340cc154402b Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Fri, 17 Dec 2021 06:51:25 +0100 Subject: [PATCH] Day 17: part 1 in bc(1) w/o programming, part 2 pretty simple --- 34.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 34.pl diff --git a/34.pl b/34.pl new file mode 100755 index 0000000..640916c --- /dev/null +++ b/34.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +use v5.16; + +my ($xmin, $xmax) = (281, 311); my ($ymin, $ymax) = (-74, -54); +# my ($xmin, $xmax) = (20, 30); my ($ymin, $ymax) = (-10, -5); + +my $count; +for my $dx (1 .. $xmax) { +for my $dy ($ymin..-$ymin) { + my ($dx0, $dy0) = ($dx, $dy); + my ($x, $y) = (0, 0); + while ($x <= $xmax && $y >= $ymin) { + if ($x >= $xmin && $x <= $xmax && $y >= $ymin && $y <= $ymax) { + $count++; + # say $dx,',', $dy; + last; + } + $x += $dx0; $y += $dy0; + if ($dx0 > 0) { $dx0-- }; + $dy0--; + } +} } + +say $count; + -- 2.43.5