diff options
| author | Polgár Márton <polgar@astron.hu> | 2022-02-01 03:05:13 +0100 |
|---|---|---|
| committer | Polgár Márton <polgar@astron.hu> | 2022-02-01 03:05:13 +0100 |
| commit | b80cf40f474856156d259a3308172b32019811fa (patch) | |
| tree | 852d0d01ce8b5aa9a4844909f821552dece8cbab | |
| parent | ebcd59a50056e1da3a3f28c98e867c2344548ac6 (diff) | |
| download | perlweeklychallenge-club-b80cf40f474856156d259a3308172b32019811fa.tar.gz perlweeklychallenge-club-b80cf40f474856156d259a3308172b32019811fa.tar.bz2 perlweeklychallenge-club-b80cf40f474856156d259a3308172b32019811fa.zip | |
2colours (initial) solutions for challenge No. 150
| -rwxr-xr-x | challenge-150/2colours/raku/ch-1.raku | 17 | ||||
| -rwxr-xr-x | challenge-150/2colours/raku/ch-2-no-use.raku | 16 | ||||
| -rwxr-xr-x | challenge-150/2colours/raku/ch-2.raku | 5 |
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-150/2colours/raku/ch-1.raku b/challenge-150/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..986d503c88 --- /dev/null +++ b/challenge-150/2colours/raku/ch-1.raku @@ -0,0 +1,17 @@ +#!/usr/bin/env raku + +use experimental :cached; +my $*a, my $*b; + +multi fibo-word(1) { $*a } +multi fibo-word(2) { $*b } +multi fibo-word($n where * > 2) is cached { fibo-word($n-2) ~ fibo-word($n-1) } + +sub MAIN( + Str $*a, #= the first starting value of the Fibonacci Word sequence + Str $*b #= the second starting value of the Fibonacci Word sequence, having equal length to $a + where { $*a.chars == $*b.chars } +) { + my $first-long = (1..*).map(&fibo-word).first(*.chars >= 51); + say "The 51st digit in the first term having at least 51 digits '$_' is {.comb[50]}." given $first-long; +} diff --git a/challenge-150/2colours/raku/ch-2-no-use.raku b/challenge-150/2colours/raku/ch-2-no-use.raku new file mode 100755 index 0000000000..0e8b3f58c3 --- /dev/null +++ b/challenge-150/2colours/raku/ch-2-no-use.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku + +constant $limit = 500; +constant @base-primes = (1..sqrt $limit).grep(&is-prime); +sub prime-factors($n is copy where 0 < * <= $limit) { + gather { + for @base-primes { + while $n %% $_ { + .take; + $n /= $_; + } + } + take $n unless $n == 1; + } +} +say "The smallest positive square-free integers are\n\t{(1..500).grep(*.&prime-factors.Bag.values.all < 2).join(', ')}"; diff --git a/challenge-150/2colours/raku/ch-2.raku b/challenge-150/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..b57b8e73c0 --- /dev/null +++ b/challenge-150/2colours/raku/ch-2.raku @@ -0,0 +1,5 @@ +#!/usr/bin/env raku + +use Prime::Factor; + +say "The smallest positive square-free integers are\n\t{(1..500).grep(*.&prime-factors.Bag.values.all < 2).join(', ')}"; |
