diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-08-07 00:34:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-07 00:34:43 +0100 |
| commit | fe214192a9af284ca282e1506e1d42ccecaee071 (patch) | |
| tree | d34e29b9b96bff0b73cd6f81ef481c3d18ba76c6 | |
| parent | ac7eebbb49334095a05b5dce7bfa89f76e3a1fc2 (diff) | |
| parent | a8d0fe22140f3e572fb12a73480cab684cd47388 (diff) | |
| download | perlweeklychallenge-club-fe214192a9af284ca282e1506e1d42ccecaee071.tar.gz perlweeklychallenge-club-fe214192a9af284ca282e1506e1d42ccecaee071.tar.bz2 perlweeklychallenge-club-fe214192a9af284ca282e1506e1d42ccecaee071.zip | |
Merge pull request #4671 from Scimon/master
Finally got Challenge 2 working
| -rw-r--r-- | challenge-124/simon-proctor/raku/ch-2.raku | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/challenge-124/simon-proctor/raku/ch-2.raku b/challenge-124/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..7f6e57d0b8 --- /dev/null +++ b/challenge-124/simon-proctor/raku/ch-2.raku @@ -0,0 +1,15 @@ +#!/usr/bin/env raku + +#| Given a list of up to 20 elements find the division of items that has the smallest difference +sub MAIN( *@N where @N.elems <= 20 ) { + my $len = @N.elems div 2; + + my @res = @N.combinations($len).map( -> @a { ( @a, (@N (-) @a).keys ) } ) + .sort(-> (@a,@b) {abs( ([+] @a) - ([+] @b)) } ) + .first; + + "{@res[0].join(',')} <=> {@res[1].join(',')}".say; + + +} + |
