diff options
| author | Simon Proctor <simon.proctor@gmail.com> | 2021-05-24 10:43:14 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@gmail.com> | 2021-05-24 10:43:14 +0100 |
| commit | badec992246cbcdb1bf37aa8a83e96e07ffe0767 (patch) | |
| tree | 79588235c438079ed1cc731618bbbe08636348ef | |
| parent | 28560a3b303405a985ae132cca022bd8e0f96a70 (diff) | |
| download | perlweeklychallenge-club-badec992246cbcdb1bf37aa8a83e96e07ffe0767.tar.gz perlweeklychallenge-club-badec992246cbcdb1bf37aa8a83e96e07ffe0767.tar.bz2 perlweeklychallenge-club-badec992246cbcdb1bf37aa8a83e96e07ffe0767.zip | |
Challenge 114
| -rw-r--r-- | challenge-114/simon-proctor/raku/ch-1.raku | 6 | ||||
| -rw-r--r-- | challenge-114/simon-proctor/raku/ch-2.raku | 9 |
2 files changed, 15 insertions, 0 deletions
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 } |
