diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-06-05 13:20:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-05 13:20:52 +0100 |
| commit | dd237535572518a21765005037007fec898c3d34 (patch) | |
| tree | d93e23742ba8ae279dd28e979a3422a92570f703 /challenge-167 | |
| parent | 418202269da09733133179b924c961bf0367b815 (diff) | |
| parent | cacaa6831cbed8d178f7d976e18b30813641c806 (diff) | |
| download | perlweeklychallenge-club-dd237535572518a21765005037007fec898c3d34.tar.gz perlweeklychallenge-club-dd237535572518a21765005037007fec898c3d34.tar.bz2 perlweeklychallenge-club-dd237535572518a21765005037007fec898c3d34.zip | |
Merge pull request #6201 from wambash/challenge-week-167
solution week 167-1
Diffstat (limited to 'challenge-167')
| -rw-r--r-- | challenge-167/wambash/raku/ch-1.raku | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-167/wambash/raku/ch-1.raku b/challenge-167/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..c8e4065dc3 --- /dev/null +++ b/challenge-167/wambash/raku/ch-1.raku @@ -0,0 +1,49 @@ +#!/usr/bin/env raku + +multi is-circular-prime ($n --> Bool) { + samewith $n.comb +} + +multi is-circular-prime (@n --> Bool) { + @n, *.rotate.cache ... * + andthen .head: @n.elems + andthen .map: *.join + andthen .all.is-prime.so +} + +multi expand ( +@a (1, *@) ) { slip |@a X, 1,3,7,9 } +multi expand ( +@a (3, *@) ) { slip |@a X, 3,7,9 } +multi expand ( +@a (7, *@) ) { slip |@a X, 7,9 } + +multi find-uniq-circular (@k where .head ~~ Int|Int(Str) ) { + samewith @k.map: *.comb +} + +multi find-uniq-circular (@n) { + @n + andthen .grep: {@^p.head == @^p.min }\ + andthen .grep: {@^p.head !== @^p.tail or [==] @^p }\ + andthen .grep: &is-circular-prime + andthen .map: *.join +} + + +multi MAIN (Bool :test($)!) { + use Test; + is is-circular-prime(113.comb ), True; + is is-circular-prime(133.comb ), False; + is is-circular-prime(193939), True; + is is-circular-prime(1193.comb ), True; + is find-uniq-circular(['1193', 11, 1 x 19]), <1193 11 1111111111111111111>; + is find-uniq-circular([1193, 1931, 1192, 9311,3119]), <1193> ; + done-testing; +} + + +multi MAIN ( :$n=6, :$s=2 ) { + (1,3,7), { .map: &expand } ... * + andthen .skip: $s + andthen .map: &find-uniq-circular + andthen .head: $n - $s + andthen .put +} |
