diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-06-07 18:13:36 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-06-07 18:13:36 +0100 |
| commit | ac32e51ae34212cd68b2cfdd8f72f54681006e29 (patch) | |
| tree | 1b07024ca5f16dedf39136e39d7188bf8877b4e6 /challenge-168 | |
| parent | 541cbe1b04d5e804d2cabe879317cff9ae3f5cb4 (diff) | |
| download | perlweeklychallenge-club-ac32e51ae34212cd68b2cfdd8f72f54681006e29.tar.gz perlweeklychallenge-club-ac32e51ae34212cd68b2cfdd8f72f54681006e29.tar.bz2 perlweeklychallenge-club-ac32e51ae34212cd68b2cfdd8f72f54681006e29.zip | |
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-168')
| -rw-r--r-- | challenge-168/robert-dicicco/julia/ch-1.jl | 37 | ||||
| -rw-r--r-- | challenge-168/robert-dicicco/perl/ch-1.pl | 47 | ||||
| -rw-r--r-- | challenge-168/robert-dicicco/perl/ch-2.pl | 51 | ||||
| -rw-r--r-- | challenge-168/robert-dicicco/raku/ch-1.raku | 41 | ||||
| -rw-r--r-- | challenge-168/robert-dicicco/raku/ch-2.raku | 51 | ||||
| -rw-r--r-- | challenge-168/robert-dicicco/ruby/ch-1.rb | 37 |
6 files changed, 264 insertions, 0 deletions
diff --git a/challenge-168/robert-dicicco/julia/ch-1.jl b/challenge-168/robert-dicicco/julia/ch-1.jl new file mode 100644 index 0000000000..45d1bbcd64 --- /dev/null +++ b/challenge-168/robert-dicicco/julia/ch-1.jl @@ -0,0 +1,37 @@ +#!julia.exe + +# AUTHOR: Robert DiCicco +# DATE: 2022-06-06 +# Challenge 168 Perrin Primes ( Julia ) + +using Primes + +perrin = [3,0,2] + +results = [] + +PRIME_COUNT = 13 + +i = 0 + +while i <= PRIME_COUNT + + slots = size(perrin,1) + + calc_val = perrin[slots - 1] + perrin[slots - 2] # since julia arrays are option base 1 + + push!(perrin,calc_val) + + if isprime(calc_val) + + push!(results,calc_val) + + global i += 1 + + end + +end + +results = unique!(sort(results)) + +println(results) diff --git a/challenge-168/robert-dicicco/perl/ch-1.pl b/challenge-168/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..b72ac33280 --- /dev/null +++ b/challenge-168/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,47 @@ +#!perl.exe + +# AUTHOR: Robert DiCicco +# DATE: 2022-06-06 +# Challenge 168 Perrin Primes ( Perl ) + +use strict; +use warnings; +use feature qw/say/; +use ntheory qw/is_prime/; +use List::MoreUtils qw(uniq); + +my @perrin = qw(3 0 2 ); # working array + +my @results = (); + +my $i = 0; + +my $PRIME_COUNT = 13; + +while($i <= $PRIME_COUNT) { + + my $slots = scalar(@perrin); + + my $calc_val = $perrin[$slots - 2] + $perrin[$slots - 3]; + + push(@perrin, $calc_val); + + if (is_prime($calc_val)) { + + push(@results, $calc_val); + + $i++; + + } + +} + +@results = sort { $a <=> $b } uniq(@results); + +foreach(@results) { + + print("$_ "); + +} + +print("\n"); diff --git a/challenge-168/robert-dicicco/perl/ch-2.pl b/challenge-168/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..8ecf170a47 --- /dev/null +++ b/challenge-168/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,51 @@ +#!perl.exe + +# AUTHOR: Robert DiCicco +# DATE: 2022-06-06 +# Challenge 168 Home Prime ( Perl ) + +use strict; +use warnings; +use ntheory qw/is_prime factor divisors/; + +my $hp = 8; +my @results; + +sub homeprime { + my $hp = shift; + + my @factors = factor($hp); + + my $hp_new = join('',@factors); + + return($hp_new); + +} + +my $flag = 1; + +push(@results, $hp); + +while ( $flag > 0) { + + my $retval = homeprime($hp); + + if ( is_prime($retval) ){ + + push(@results, $retval); + + $flag = 0; + + } else { + + push(@results, $retval); + + $hp = $retval; + + } + +} + + print ("@results "); + + print("\n"); diff --git a/challenge-168/robert-dicicco/raku/ch-1.raku b/challenge-168/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..acfda4039c --- /dev/null +++ b/challenge-168/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,41 @@ +use v6; + +# AUTHOR: Robert DiCicco +# DATE: 2022-06-06 +# Challenge 168 Perrin Primes ( Raku ) + +my @perrin = (3,0,2); + +my @results = (); + +my $PRIME_COUNT = 13; + +my $i = 0; + +while $i <= $PRIME_COUNT { + + my $slots = @perrin.elems; + + my $calc_val = @perrin[$slots - 2] + @perrin[$slots - 3]; + + @perrin.push: $calc_val; + + if $calc_val.is-prime { + + @results.push: $calc_val; + + $i++; + + } + +} + +@results = @results.sort.unique; + +for @results -> $val { + + print "$val "; + +} + +say ' '; diff --git a/challenge-168/robert-dicicco/raku/ch-2.raku b/challenge-168/robert-dicicco/raku/ch-2.raku new file mode 100644 index 0000000000..1db7b563b2 --- /dev/null +++ b/challenge-168/robert-dicicco/raku/ch-2.raku @@ -0,0 +1,51 @@ +use v6; + +# AUTHOR: Robert DiCicco +# DATE: 2022-06-06 +# Challenge 168 Home Primes ( Raku ) + +use Prime::Factor; + +my @results; + +sub homeprime( $hp) { + + my @factors = prime-factors($hp); + + return(@factors.join); + +} + +my $hp = 8; + +my $flag = 1; + +@results.push: $hp; + +while $flag > 0 { + + my $retval = homeprime($hp); + + if $retval.is-prime { + + @results.push: $retval; + + $flag = 0; + + } else { + + @results.push: $retval; + + $hp = $retval; + + } + +} + +for @results -> $val { + + print "$val "; + +} + +say ' '; diff --git a/challenge-168/robert-dicicco/ruby/ch-1.rb b/challenge-168/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..0a050d6120 --- /dev/null +++ b/challenge-168/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,37 @@ +#!ruby.exe + +# AUTHOR: Robert DiCicco +# DATE: 2022-06-06 +# Challenge 168 Perrin Primes ( Ruby ) + +require 'prime' + +perrin = Array[3,0,2] + +PRIME_COUNT = 14 + +results = Array.new() + +i = 0 + +while i < PRIME_COUNT + + slots = perrin.length() + + calc_val = perrin[slots - 2] + perrin[slots - 3] + + perrin.push(calc_val) + + if Prime.prime?(calc_val) + + results.push(calc_val) + + i += 1 + + end + +end + +results = results.sort.uniq + +puts "#{results }" |
