diff options
| author | Polgár Márton <polgar@astron.hu> | 2022-05-12 13:36:42 +0200 |
|---|---|---|
| committer | Polgár Márton <polgar@astron.hu> | 2022-05-12 13:36:42 +0200 |
| commit | 0cf3f8f9d8b3eb39995cb408ed905818f759bf54 (patch) | |
| tree | bce69717629d2dd495a58906ab7f6ba91c7f37be /challenge-164/2colours | |
| parent | bf592b9181f495959b5f7c1264c8c4223c269b5e (diff) | |
| download | perlweeklychallenge-club-0cf3f8f9d8b3eb39995cb408ed905818f759bf54.tar.gz perlweeklychallenge-club-0cf3f8f9d8b3eb39995cb408ed905818f759bf54.tar.bz2 perlweeklychallenge-club-0cf3f8f9d8b3eb39995cb408ed905818f759bf54.zip | |
Added weekly Raku solution @2colours
Diffstat (limited to 'challenge-164/2colours')
| -rwxr-xr-x | challenge-164/2colours/raku/ch-1.raku | 7 | ||||
| -rwxr-xr-x | challenge-164/2colours/raku/ch-2.raku | 18 |
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-164/2colours/raku/ch-1.raku b/challenge-164/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..694921a8d2 --- /dev/null +++ b/challenge-164/2colours/raku/ch-1.raku @@ -0,0 +1,7 @@ +#!/usr/bin/env raku + +sub is-palindrome($num) { + $_ ~~ .reverse given $num.comb.List +} + +(^1000).grep: { .is-prime && .&is-palindrome } andthen .join: ', ' andthen .say; diff --git a/challenge-164/2colours/raku/ch-2.raku b/challenge-164/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..415a910a58 --- /dev/null +++ b/challenge-164/2colours/raku/ch-2.raku @@ -0,0 +1,18 @@ +#!/usr/bin/env raku + +sub is-happy-proactive($num) { + state %happy-cache; + without %happy-cache{$num} { + my @sequence-until-period <== $num, *.comb.map(* ** 2).sum ... * + andthen [\,] $_ + andthen .toggle: !*.repeated + andthen .tail; + %happy-cache{$_} = * xx (.tail == 1) given @sequence-until-period; + } + %happy-cache{$num} +} + +(^Inf).grep: &is-happy-proactive + andthen .head: 8 + andthen .join: ', ' + andthen .say;
\ No newline at end of file |
