aboutsummaryrefslogtreecommitdiff
path: root/challenge-079/mohammad-anwar/raku/ch-1.t
blob: 00dacde3c3a12a1b0cb9add8867ec69f07caaa2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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;
}