diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-03-13 18:31:49 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-03-13 18:31:49 +0000 |
| commit | c96f9bfed6ec99b76a94b187a567b93429ad3944 (patch) | |
| tree | c3dd7effbb39ee8713913b3955b2905f250e0b6b /challenge-155 | |
| parent | d811849c01e880ca7e77353eed21ef84b65081ea (diff) | |
| download | perlweeklychallenge-club-c96f9bfed6ec99b76a94b187a567b93429ad3944.tar.gz perlweeklychallenge-club-c96f9bfed6ec99b76a94b187a567b93429ad3944.tar.bz2 perlweeklychallenge-club-c96f9bfed6ec99b76a94b187a567b93429ad3944.zip | |
- Added solutions by Mark Senn.
Diffstat (limited to 'challenge-155')
| -rw-r--r-- | challenge-155/mark-senn/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-155/mark-senn/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-155/mark-senn/raku/ch-1.raku | 34 | ||||
| -rw-r--r-- | challenge-155/mark-senn/raku/ch-2.raku | 28 |
4 files changed, 64 insertions, 0 deletions
diff --git a/challenge-155/mark-senn/blog.txt b/challenge-155/mark-senn/blog.txt new file mode 100644 index 0000000000..ce08715cd1 --- /dev/null +++ b/challenge-155/mark-senn/blog.txt @@ -0,0 +1 @@ +https://engineering.purdue.edu/~mark/twc-155-1.pdf diff --git a/challenge-155/mark-senn/blog1.txt b/challenge-155/mark-senn/blog1.txt new file mode 100644 index 0000000000..d9fe46e510 --- /dev/null +++ b/challenge-155/mark-senn/blog1.txt @@ -0,0 +1 @@ +https://engineering.purdue.edu/~mark/twc-155-2.pdf diff --git a/challenge-155/mark-senn/raku/ch-1.raku b/challenge-155/mark-senn/raku/ch-1.raku new file mode 100644 index 0000000000..d05e942b93 --- /dev/null +++ b/challenge-155/mark-senn/raku/ch-1.raku @@ -0,0 +1,34 @@ +use v6.d; + +# Print the first 8 unique and sorted Fortunate Numbers. +my $n = 8; + +# Guess that first 50 primes and primorials will give +# the first 8 unique and sorted Fortunate Numbers. +my $nn = 50; + +# Get the first nn primes. +my @prime = (2..*).grep(&is-prime).head($nn); + +# Compute the first nn primorials. +my @primorial; +@primorial[0]= @prime[0]; +for (1..^$nn) +{ + @primorial[$_] = @primorial[$_-1] * @prime[$_]; +} + +# Save the first $nn m's. +my @m = (); +# Loop through the first nn primorials. +for (0..^$nn) -> $i +{ + # For each primorial check if it plus m is prime, for m = 2 to whatever. + for (2..*) -> $m + { + (@primorial[$i] + $m).is-prime and @m.push($m), last; + } +} + +# Print the first 8 unique and sorted Fortunate Numbers. +@m.unique.sort.head(8).join(', ').say; diff --git a/challenge-155/mark-senn/raku/ch-2.raku b/challenge-155/mark-senn/raku/ch-2.raku new file mode 100644 index 0000000000..c87073081f --- /dev/null +++ b/challenge-155/mark-senn/raku/ch-2.raku @@ -0,0 +1,28 @@ +# Use Raku version 6.d. +use v6.d; + +# Find the period of the 3rd Pisano period. +my $modulo = 3; + +# Define a Fibonacci series (called sequence in Raku). +# The last number in the series is the first number greater than 10,000. +my $fibonacci := 0, 1, -> $a, $b {$a + $b} ... -> $a {$a > 10_000}; + +# Compute the Fibonacci series modulo $modulo. +my @modulo = $fibonacci >>%>> $modulo; + +# Find the period. +# Test periods from 2 to whatever. +for (2..*) -> $period +{ + # Divide @modulo into groups of period using ".rotor($period)"---groups + # with fewer than period elements are ignored. + # See + # https://docs.raku.org/language/operators#infix_eqv + # for information about "eqv". + # "[eqv] (1,2,3,4)" is equivalent to "1 eqv 2 eqv 3 eqv 4". + # "[eqv] ((1,2), (3,4))" is equivalent to "(1,2) eqv (3,4)". + # If all groups are equal that is the period. + + [eqv] @modulo.rotor($period) and $period.say, last; +}2 |
