diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-05-04 09:39:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-04 09:39:47 +0100 |
| commit | 9b660325f5dd72c0222bb5d4dc829c3e834aaf23 (patch) | |
| tree | a21d3edbb6323d4207a1d10d9e909623626555a9 /challenge-059 | |
| parent | 856f56ef0cfd271b4c82090f140f65ce163ea709 (diff) | |
| parent | 4b68761f4e70df055e849a1cb9c6095fea4bbf3b (diff) | |
| download | perlweeklychallenge-club-9b660325f5dd72c0222bb5d4dc829c3e834aaf23.tar.gz perlweeklychallenge-club-9b660325f5dd72c0222bb5d4dc829c3e834aaf23.tar.bz2 perlweeklychallenge-club-9b660325f5dd72c0222bb5d4dc829c3e834aaf23.zip | |
Merge pull request #1664 from Scimon/master
Starting on Challenge 2 this week.
Diffstat (limited to 'challenge-059')
| -rw-r--r-- | challenge-059/simon-proctor/raku/ch-2.raku | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-059/simon-proctor/raku/ch-2.raku b/challenge-059/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..224906b720 --- /dev/null +++ b/challenge-059/simon-proctor/raku/ch-2.raku @@ -0,0 +1,17 @@ +#!/usr/bin/env raku + +use v6; + +multi sub bit-diff( UInt $a, UInt $b where $a >= $b ) { + [+] ($a.base(2).comb.reverse Z (|$b.base(2).comb.reverse, |(lazy gather { take 0 }) ) ).map( { abs( $^a[0] - $^a[1] ) } ); +} + +multi sub bit-diff( UInt $a, UInt $b ) { bit-diff( $b, $a ) } + +#| Give the sum of the differences in bits between all the combinations of inputs +sub MAIN ( + *@vals where { $_.all ~~ UInt } #= Integer values to combine +){ + say [+] @vals.combinations(2).map( { bit-diff( |@_ ) } ); +} + |
