diff options
| author | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-05-04 09:36:33 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-05-04 09:36:33 +0100 |
| commit | 4b68761f4e70df055e849a1cb9c6095fea4bbf3b (patch) | |
| tree | eaa626493e0cfaf9691fb3b0a18fa0b59334fa45 /challenge-059 | |
| parent | 67cdd35efcf8c026c738ede53dcf8662282fbe29 (diff) | |
| download | perlweeklychallenge-club-4b68761f4e70df055e849a1cb9c6095fea4bbf3b.tar.gz perlweeklychallenge-club-4b68761f4e70df055e849a1cb9c6095fea4bbf3b.tar.bz2 perlweeklychallenge-club-4b68761f4e70df055e849a1cb9c6095fea4bbf3b.zip | |
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( |@_ ) } ); +} + |
