aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-24 10:55:57 +0100
committerGitHub <noreply@github.com>2021-05-24 10:55:57 +0100
commit8944c2b39e3c63ece8bc1d8c77003f9c04e1cdce (patch)
tree5aa2021820e677d5a196150a314ef8d3120c5d3f
parent85b94041773808c482635b620984560e118bf9c0 (diff)
parentbadec992246cbcdb1bf37aa8a83e96e07ffe0767 (diff)
downloadperlweeklychallenge-club-8944c2b39e3c63ece8bc1d8c77003f9c04e1cdce.tar.gz
perlweeklychallenge-club-8944c2b39e3c63ece8bc1d8c77003f9c04e1cdce.tar.bz2
perlweeklychallenge-club-8944c2b39e3c63ece8bc1d8c77003f9c04e1cdce.zip
Merge pull request #4133 from Scimon/master
Hey
-rw-r--r--challenge-112/simon-proctor/raku/ch-2.raku31
-rw-r--r--challenge-114/simon-proctor/raku/ch-1.raku6
-rw-r--r--challenge-114/simon-proctor/raku/ch-2.raku9
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 }