diff options
| author | Andrey Shitov <ash@Andreys-iMac.local> | 2023-07-24 11:39:14 +0300 |
|---|---|---|
| committer | Andrey Shitov <ash@Andreys-iMac.local> | 2023-07-24 11:39:14 +0300 |
| commit | 6b772cb64e72b62bb70c30b130ddf85a42d95342 (patch) | |
| tree | a0996a6fd813a44bbb78762b276a8cd9b17b1be5 /challenge-227/ash | |
| parent | e4bdf5dcb6e741f1fb8e1b145fd2111f05ed6445 (diff) | |
| download | perlweeklychallenge-club-6b772cb64e72b62bb70c30b130ddf85a42d95342.tar.gz perlweeklychallenge-club-6b772cb64e72b62bb70c30b130ddf85a42d95342.tar.bz2 perlweeklychallenge-club-6b772cb64e72b62bb70c30b130ddf85a42d95342.zip | |
ash-227, task 1 in Raku
Diffstat (limited to 'challenge-227/ash')
| -rw-r--r-- | challenge-227/ash/raku/ch-1.raku | 42 | ||||
| -rw-r--r-- | challenge-227/ash/raku/ch-1a.raku | 12 | ||||
| -rw-r--r-- | challenge-227/ash/raku/ch-1b.raku | 7 |
3 files changed, 61 insertions, 0 deletions
diff --git a/challenge-227/ash/raku/ch-1.raku b/challenge-227/ash/raku/ch-1.raku new file mode 100644 index 0000000000..7adc344024 --- /dev/null +++ b/challenge-227/ash/raku/ch-1.raku @@ -0,0 +1,42 @@ +# Solution to the Task 1 of the Weekly Challenge 227 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-227/#TASK1 + +# Explanations: +# https://andrewshitov.com/2023/07/24/counting-friday-the-13th-in-raku/ + +# Test run: +# $ raku ch-1.raku +# There are 2 Fridays the 13th in 2023: +# 01-13-2023 +# 10-13-2023 + +# $ raku ch-1.raku 2021 +# There is only one Friday the 13th in 2021: +# 08-13-2021 + + +my $year = @*ARGS[0] // 2023; + +my @dates; +for 1..12 -> $month { + my $dt = DateTime.new(year => $year, month => $month, day => 13); + if ($dt.day-of-week == 5) { + push @dates, $dt; + } +} + +if @dates { + my $count = @dates.elems; + + if $count == 1 { + say "There is only one Friday the 13th in $year:"; + } + else { + say "There are {@dates.elems} Fridays the 13th in $year:"; + } + + .mm-dd-yyyy.say for @dates; +} +else { + say "There are no Friday the 13th in $year."; +} diff --git a/challenge-227/ash/raku/ch-1a.raku b/challenge-227/ash/raku/ch-1a.raku new file mode 100644 index 0000000000..d81d426e9f --- /dev/null +++ b/challenge-227/ash/raku/ch-1a.raku @@ -0,0 +1,12 @@ +sub count-friday-the13s($year) { + my $count = 0; + + for 1..12 -> $month { + my $dt = DateTime.new(year => $year, month => $month, day => 13); + $count++ if $dt.day-of-week == 5; + } + + return $count; +} + +say count-friday-the13s(2023); diff --git a/challenge-227/ash/raku/ch-1b.raku b/challenge-227/ash/raku/ch-1b.raku new file mode 100644 index 0000000000..faf8d4516d --- /dev/null +++ b/challenge-227/ash/raku/ch-1b.raku @@ -0,0 +1,7 @@ +sub count-friday-the13s($year) { + [+] map { + 5 == DateTime.new(year => $year, month => $_, day => 13).day-of-week + }, 1..12; +} + +say count-friday-the13s(2023); |
