diff options
| author | Aaron Smith <aaronreidsmith@gmail.com> | 2021-04-10 15:19:50 -0500 |
|---|---|---|
| committer | Aaron Smith <aaronreidsmith@gmail.com> | 2021-04-10 15:19:50 -0500 |
| commit | 88e9c609e4fa14904a19ee2ba96cd4edfeaf9a1b (patch) | |
| tree | 974a540136f3748d091f8ed5b7838beee701702a /challenge-107 | |
| parent | 0eb9b07380a5109e844229d71368605077a2109f (diff) | |
| download | perlweeklychallenge-club-88e9c609e4fa14904a19ee2ba96cd4edfeaf9a1b.tar.gz perlweeklychallenge-club-88e9c609e4fa14904a19ee2ba96cd4edfeaf9a1b.tar.bz2 perlweeklychallenge-club-88e9c609e4fa14904a19ee2ba96cd4edfeaf9a1b.zip | |
Challenge 107 - Raku
Diffstat (limited to 'challenge-107')
| -rw-r--r-- | challenge-107/aaronreidsmith/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-107/aaronreidsmith/raku/ch-1.raku | 28 | ||||
| -rw-r--r-- | challenge-107/aaronreidsmith/raku/ch-2.raku | 26 |
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-107/aaronreidsmith/blog.txt b/challenge-107/aaronreidsmith/blog.txt new file mode 100644 index 0000000000..5a2db6abfc --- /dev/null +++ b/challenge-107/aaronreidsmith/blog.txt @@ -0,0 +1 @@ +https://aaronreidsmith.github.io/blog/perl-weekly-challenge-107/ diff --git a/challenge-107/aaronreidsmith/raku/ch-1.raku b/challenge-107/aaronreidsmith/raku/ch-1.raku new file mode 100644 index 0000000000..7a47f44ccf --- /dev/null +++ b/challenge-107/aaronreidsmith/raku/ch-1.raku @@ -0,0 +1,28 @@ +#!/usr/bin/env raku + +sub challenge(Int $n) returns Str { + my @output; + for (^∞) -> $i { + my @digits = $i.comb; + my $valid = True; + for @digits.kv -> $index, $value { + $valid = @digits.grep($index).elems == $value; + last unless $valid; + } + @output.push($i) if $valid; + last if @output.elems == $n; + } + @output.join(', '); +} + +multi sub MAIN(Int $n = 3) { + say challenge($n); +} + +multi sub MAIN(Bool :$test) { + use Test; + + is(challenge(3), '1210, 2020, 21200'); + + done-testing; +} diff --git a/challenge-107/aaronreidsmith/raku/ch-2.raku b/challenge-107/aaronreidsmith/raku/ch-2.raku new file mode 100644 index 0000000000..a199bfadc1 --- /dev/null +++ b/challenge-107/aaronreidsmith/raku/ch-2.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku + +# Used for testing +class Calc { + method add {} + method mul {} + method div {} +} + +sub challenge(Any $class) returns Str { + $class.^methods.map(*.gist).join("\n"); +} + +multi sub MAIN(Bool :$main) { + say challenge(Calc.new); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my $test-class = Calc.new; + + is(challenge($test-class), "add\nmul\ndiv\nBUILDALL"); + + done-testing; +} |
