aboutsummaryrefslogtreecommitdiff
path: root/challenge-114
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-28 16:00:41 +0100
committerGitHub <noreply@github.com>2021-05-28 16:00:41 +0100
commit65002fd784f97a4cb1d88cc8972b0c7c6e85c28a (patch)
treeeb62bdcd16576ae62aabed87bda2d6b0e0a6abbd /challenge-114
parentb2d170df6ba9e49797342f20da3fffbc37fb6c6a (diff)
parent58d6182e0fa2f922a19fc040ab7f8d4babe0f5f5 (diff)
downloadperlweeklychallenge-club-65002fd784f97a4cb1d88cc8972b0c7c6e85c28a.tar.gz
perlweeklychallenge-club-65002fd784f97a4cb1d88cc8972b0c7c6e85c28a.tar.bz2
perlweeklychallenge-club-65002fd784f97a4cb1d88cc8972b0c7c6e85c28a.zip
Merge pull request #4154 from aaronreidsmith/challenge-114
Challenge 114 - Raku
Diffstat (limited to 'challenge-114')
-rw-r--r--challenge-114/aaronreidsmith/blog.txt1
-rw-r--r--challenge-114/aaronreidsmith/raku/ch-1.raku24
-rw-r--r--challenge-114/aaronreidsmith/raku/ch-2.raku30
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;
+}