From badec992246cbcdb1bf37aa8a83e96e07ffe0767 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 24 May 2021 10:43:14 +0100 Subject: Challenge 114 --- challenge-114/simon-proctor/raku/ch-1.raku | 6 ++++++ challenge-114/simon-proctor/raku/ch-2.raku | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 challenge-114/simon-proctor/raku/ch-1.raku create mode 100644 challenge-114/simon-proctor/raku/ch-2.raku 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 } -- cgit