diff options
| -rw-r--r-- | challenge-112/simon-proctor/raku/ch-2.raku | 31 | ||||
| -rw-r--r-- | challenge-114/simon-proctor/raku/ch-1.raku | 6 | ||||
| -rw-r--r-- | challenge-114/simon-proctor/raku/ch-2.raku | 9 |
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-112/simon-proctor/raku/ch-2.raku b/challenge-112/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..237faa8cdb --- /dev/null +++ b/challenge-112/simon-proctor/raku/ch-2.raku @@ -0,0 +1,31 @@ +#!/usr/bin/env raku + + +my %*SUB-MAIN-OPTS = :named-anywhere, :bundling; + +#| Brute force find the steps +multi sub MAIN( $a, :brute(:$b) where ?* ) { + .join(" + ").say for (|(1 xx $a) ,|(2 xx $a)).combinations().unique( as => *.join(",")).grep( -> @a { ([+] @a) == $a } ).map( -> @a { | @a.permutations().unique( as => *.join(",") ) } ); +} + +#| Use Recursion to find the options +multi sub MAIN( $a, :recurse(:$r) where ?* ) { + .say for find-steps( $a, [] ); +} + +multi sub MAIN( $a ) { + MAIN( $a, :r ); +} + +multi sub find-steps( 0, @l ) { + return @l.join( " + " ); +} + +multi sub find-steps( 1, @l ) { + return [ |@l, 1 ].join( " + " ); +} + +multi sub find-steps( $v , @l ) { + return [ |find-steps( $v-1, [ |@l, 1 ] ), + |find-steps( $v-2, [ |@l, 2 ] ) ]; +} diff --git a/challenge-114/simon-proctor/raku/ch-1.raku b/challenge-114/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..38c1422058 --- /dev/null +++ b/challenge-114/simon-proctor/raku/ch-1.raku @@ -0,0 +1,6 @@ +#!/usr/bin/env raku + +#| Find the nest highest integer that's a palindrome +sub MAIN( Int $N ) { + ($N^..*).first( { $_ ~~ $_.flip } ).say +} diff --git a/challenge-114/simon-proctor/raku/ch-2.raku b/challenge-114/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..f299414df6 --- /dev/null +++ b/challenge-114/simon-proctor/raku/ch-2.raku @@ -0,0 +1,9 @@ +#!/usr/bin/env raku + +#| Given a number find the next highest number which has the same number of ones in the binary rep +sub MAIN ( Int $N ) { + my $ones = one-count( $N ); + ($N^..*).first( { $ones == one-count($_) } ).say; +} + +sub one-count( Int $n ) { $n.base(2).comb.grep( * == 1 ).elems } |
