aboutsummaryrefslogtreecommitdiff
path: root/challenge-079
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-079')
-rw-r--r--challenge-079/mohammad-anwar/raku/ch-1.raku23
-rw-r--r--challenge-079/mohammad-anwar/raku/ch-1.t26
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-079/mohammad-anwar/raku/ch-1.raku b/challenge-079/mohammad-anwar/raku/ch-1.raku
new file mode 100644
index 0000000000..ad0a1be4de
--- /dev/null
+++ b/challenge-079/mohammad-anwar/raku/ch-1.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+#
+# Perl Weekly Challenge - 079
+#
+# Task #1: Count Set Bits
+#
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-079
+#
+
+use v6.d;
+
+sub MAIN(Int :$N = 4) { count-set-bits($N).say }
+
+#
+#
+# SUBROUTINE
+
+sub count-set-bits(Int $n) {
+ my $c = 0;
+ (1..$n).map( -> $i { $c += [+] $i.base(2).comb; });
+ return $c % 1000000007;
+}
diff --git a/challenge-079/mohammad-anwar/raku/ch-1.t b/challenge-079/mohammad-anwar/raku/ch-1.t
new file mode 100644
index 0000000000..00dacde3c3
--- /dev/null
+++ b/challenge-079/mohammad-anwar/raku/ch-1.t
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+#
+# Perl Weekly Challenge - 079
+#
+# Task #1: Count Set Bits
+#
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-079
+#
+
+use Test;
+
+is count-set-bits(4), 5, "testing example 1";
+is count-set-bits(3), 4, "testing example 2";
+
+done-testing;
+
+#
+#
+# SUBROUTINE
+
+sub count-set-bits(Int $n) {
+ my $c = 0;
+ (1..$n).map( -> $i { $c += [+] $i.base(2).comb; });
+ return $c % 1000000007;
+}