From 41525f249c3d65cfcf21f8a0a9f29208c7a54da3 Mon Sep 17 00:00:00 2001 From: Niels van Dijke Date: Tue, 20 Sep 2022 23:08:29 +0000 Subject: Task 2 - more compact code --- challenge-183/perlboy1967/perl/ch-2.pl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/challenge-183/perlboy1967/perl/ch-2.pl b/challenge-183/perlboy1967/perl/ch-2.pl index 33da26f65d..513f76d87a 100755 --- a/challenge-183/perlboy1967/perl/ch-2.pl +++ b/challenge-183/perlboy1967/perl/ch-2.pl @@ -37,14 +37,9 @@ sub dateDifference($$) { my $year = DateTime::Duration->new(years => 1); my $y = 0; - while ($f < $t) { + while ($f <= $t - $year) { + $f += $year; $y++; - $f->add_duration($year); - if ($f > $t) { - $y--; - $f->subtract_duration($year); - last; - } } return [$y,$f->delta_days($t)->{days}]; -- cgit