aboutsummaryrefslogtreecommitdiff
path: root/challenge-107
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-11 01:59:04 +0100
committerGitHub <noreply@github.com>2021-04-11 01:59:04 +0100
commit73272a063d7941a48c60fd07f4998a3b7bdbbfc9 (patch)
tree09f3c39eff7eb7221377dacdd1d6914e61a58b4f /challenge-107
parentb044c835fd4fdcd2aa41ccb09a052f6a2538b643 (diff)
parent88e9c609e4fa14904a19ee2ba96cd4edfeaf9a1b (diff)
downloadperlweeklychallenge-club-73272a063d7941a48c60fd07f4998a3b7bdbbfc9.tar.gz
perlweeklychallenge-club-73272a063d7941a48c60fd07f4998a3b7bdbbfc9.tar.bz2
perlweeklychallenge-club-73272a063d7941a48c60fd07f4998a3b7bdbbfc9.zip
Merge pull request #3857 from aaronreidsmith/challenge-107
Challenge 107 - Raku
Diffstat (limited to 'challenge-107')
-rw-r--r--challenge-107/aaronreidsmith/blog.txt1
-rw-r--r--challenge-107/aaronreidsmith/raku/ch-1.raku28
-rw-r--r--challenge-107/aaronreidsmith/raku/ch-2.raku26
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;
+}