diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-23 00:41:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-23 00:41:59 +0100 |
| commit | 005671c96b9b4b8e74253b4e508b018bf02278d5 (patch) | |
| tree | 3257c988a0104d6d10fe89d932aa408b70780749 | |
| parent | 92be2a7c56efdb9eac6cd183c3b5d2edd6e360f8 (diff) | |
| parent | e2f2ffd5a1b92b482edf0ae7e975d434685b12e8 (diff) | |
| download | perlweeklychallenge-club-005671c96b9b4b8e74253b4e508b018bf02278d5.tar.gz perlweeklychallenge-club-005671c96b9b4b8e74253b4e508b018bf02278d5.tar.bz2 perlweeklychallenge-club-005671c96b9b4b8e74253b4e508b018bf02278d5.zip | |
Merge pull request #12218 from BarrOff/barroff-326
feat: add solution for challenge 325 from BarrOff
| -rw-r--r-- | challenge-325/barroff/raku/ch-1.p6 | 25 | ||||
| -rw-r--r-- | challenge-326/barroff/raku/ch-1.p6 | 24 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-325/barroff/raku/ch-1.p6 b/challenge-325/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..52f7d5aefe --- /dev/null +++ b/challenge-325/barroff/raku/ch-1.p6 @@ -0,0 +1,25 @@ +#!/usr/bin/env raku + +use v6.d; + +sub consecutive-one(@binary --> Int) { + return 0 unless 1 ∈ @binary; + max(map({ $_.chars }, @binary.join.split('0'))); +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is consecutive-one([0, 1, 1, 0, 1, 1, 1]), 3, + 'Works for ([0, 1, 1, 0, 1, 1, 1])'; + is consecutive-one([0, 0, 0, 0]), 0, + 'Works for ([0, 0, 0, 0])'; + is consecutive-one([1, 0, 1, 0, 1, 1]), 2, 'Works for ([1, 0, 1, 0, 1, 1])'; +} + +#| Take user provided list like 1 1 0 0 1 1 1 0 1 +multi sub MAIN(*@binary) { + say consecutive-one(@binary); +} diff --git a/challenge-326/barroff/raku/ch-1.p6 b/challenge-326/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..781f05f607 --- /dev/null +++ b/challenge-326/barroff/raku/ch-1.p6 @@ -0,0 +1,24 @@ +#!/usr/bin/env raku + +use v6.d; + +sub day-of-the-year(Str $date --> Int) { + my $end-date = Date.new($date); + my $start-date = Date.new($end-date.year, 1, 1); + $end-date - $start-date + 1; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is day-of-the-year('2025-02-02'), 33, 'works for "2025-02-02"'; + is day-of-the-year('2025-04-10'), 100, 'works for "2025-04-10"'; + is day-of-the-year('2025-09-07'), 250, 'works for "2025-09-07"'; +} + +#| Take user provided string like 2025-02-02 +multi sub MAIN(Str $date) { + say day-of-the-year($date); +} |
