diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2022-09-20 23:08:29 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2022-09-20 23:08:29 +0000 |
| commit | 41525f249c3d65cfcf21f8a0a9f29208c7a54da3 (patch) | |
| tree | 6e20bd2ce5449227eb5fe703bf22ae004e070202 | |
| parent | 0bb6e076e6247817844ff7be0b33f8e1a191e812 (diff) | |
| download | perlweeklychallenge-club-41525f249c3d65cfcf21f8a0a9f29208c7a54da3.tar.gz perlweeklychallenge-club-41525f249c3d65cfcf21f8a0a9f29208c7a54da3.tar.bz2 perlweeklychallenge-club-41525f249c3d65cfcf21f8a0a9f29208c7a54da3.zip | |
Task 2 - more compact code
| -rwxr-xr-x | challenge-183/perlboy1967/perl/ch-2.pl | 9 |
1 files 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}]; |
