From 86b65c6eff35fba1c8cf415649c6503b668c0f86 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 17 Feb 2020 09:21:45 +0100 Subject: Task 2 done. --- challenge-048/luca-ferrari/raku/ch-2.p6 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-048/luca-ferrari/raku/ch-2.p6 (limited to 'challenge-048') 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 +# +# 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; + } + +} -- cgit