diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2020-02-17 09:21:45 +0100 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2020-02-17 09:21:45 +0100 |
| commit | 86b65c6eff35fba1c8cf415649c6503b668c0f86 (patch) | |
| tree | 4be22bac0499c9608cc60b595165028ab05ed51c /challenge-048 | |
| parent | 49ac62fb8c77fac685a2e1ab5d04e8dac44bf8dd (diff) | |
| download | perlweeklychallenge-club-86b65c6eff35fba1c8cf415649c6503b668c0f86.tar.gz perlweeklychallenge-club-86b65c6eff35fba1c8cf415649c6503b668c0f86.tar.bz2 perlweeklychallenge-club-86b65c6eff35fba1c8cf415649c6503b668c0f86.zip | |
Task 2 done.
Diffstat (limited to 'challenge-048')
| -rw-r--r-- | challenge-048/luca-ferrari/raku/ch-2.p6 | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-048/luca-ferrari/raku/ch-2.p6 b/challenge-048/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..89f23ca19b --- /dev/null +++ b/challenge-048/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,31 @@ +#!env perl6 +# Perl Weekly Challenge 48 +# see <https://perlweeklychallenge.org/blog/perl-weekly-challenge-048/> +# +# Task 2 +# Palindrome Dates +# +# Write a script to print all Palindrome Dates between 2000 and 2999. +# The format of date is mmddyyyy. +# For example, the first one was on October 2, 2001 as it is represented as 10022001. + + + +sub MAIN( Int :$year-start? = 2000, + Int :$year-end? = 2999 ) { + + + my $current-date = Date.new( :year( $year-start ), + :day(1), + :month(1), + formatter => { sprintf( "%02d%02d%04d", .month, .day, .year ) } ); + my $end-date = Date.new( :year( $year-end ), :day(31), :month(12) ); + + for 1 .. $end-date - $current-date { + $current-date += 1; # add one day at a time + # print the date if its string representation is the same as + # the flipped string representation + "Palindrome: $current-date".say if $current-date.Str ~~ $current-date.Str.flip; + } + +} |
