commit f29c58f1c84aab86fabe76e94672108b1bd084b4 parent 885052fd663bf4c78442c7723f7e3368bb98c78d Author: Samir Parikh <noreply@samirparikh.com> Date: Sat, 5 Mar 2022 13:53:05 +0000 update solution to note use DateTime module Diffstat:
M | leap/Leap.pm | | | 9 | ++++----- |
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/leap/Leap.pm b/leap/Leap.pm @@ -4,14 +4,13 @@ use strict; use warnings; use Exporter qw<import>; our @EXPORT_OK = qw<is_leap_year>; -use DateTime; # definitely cheating! sub is_leap_year { my ($year) = @_; - my $dt = DateTime->new( - year => $year, - ); - return $dt->is_leap_year; + return 0 if $year % 4; # year is not divisible by 4 + return 1 if $year % 100; # year is divisible by 4 but not 100 + return 0 if $year % 400; # year is divisible by 4 and 100 but not 400 + return 1; # divisible by 400 } 1;