diff options
Diffstat (limited to 'challenge-114')
| -rw-r--r-- | challenge-114/aaronreidsmith/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-114/aaronreidsmith/raku/ch-1.raku | 24 | ||||
| -rw-r--r-- | challenge-114/aaronreidsmith/raku/ch-2.raku | 30 |
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-114/aaronreidsmith/blog.txt b/challenge-114/aaronreidsmith/blog.txt new file mode 100644 index 0000000000..8bb2dc2414 --- /dev/null +++ b/challenge-114/aaronreidsmith/blog.txt @@ -0,0 +1 @@ +https://aaronreidsmith.github.io/blog/perl-weekly-challenge-114/ diff --git a/challenge-114/aaronreidsmith/raku/ch-1.raku b/challenge-114/aaronreidsmith/raku/ch-1.raku new file mode 100644 index 0000000000..5e67985a5f --- /dev/null +++ b/challenge-114/aaronreidsmith/raku/ch-1.raku @@ -0,0 +1,24 @@ +#!/usr/bin/env raku + +sub challenge(Int $N) returns Int { + ($N^..Inf).first(-> $num { $num == $num.flip }, :v); +} + +multi sub MAIN(Int $N) { + say challenge($N); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my @tests = ( + (1234, 1331), + (999, 1001) + ); + + for @tests -> ($N, $expected) { + is(challenge($N), $expected); + } + + done-testing; +} diff --git a/challenge-114/aaronreidsmith/raku/ch-2.raku b/challenge-114/aaronreidsmith/raku/ch-2.raku new file mode 100644 index 0000000000..20d191d790 --- /dev/null +++ b/challenge-114/aaronreidsmith/raku/ch-2.raku @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +sub bits(Int $base-ten) returns Int { + $base-ten.base(2).comb.grep(* eq '1').elems; +} + +sub challenge(Int $N where $N > 0) returns Int { + my $bits = bits($N); + ($N^..Inf).first(-> $num { bits($num) == $bits }, :v); +} + +multi sub MAIN(Int $N) { + say challenge($N); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my @tests = ( + (1, 2), + (3, 5), + (12, 17) + ); + + for @tests -> ($N, $expected) { + is(challenge($N), $expected); + } + + done-testing; +} |
