diff options
| author | Ruben Westerberg <drclaw@mac.com> | 2019-04-14 12:15:36 +1000 |
|---|---|---|
| committer | Ruben Westerberg <drclaw@mac.com> | 2019-04-14 12:15:36 +1000 |
| commit | 107bdf42f90c5c0d55f7c92cc0959ac54a151244 (patch) | |
| tree | a1076506efc2af0a5763ec47ba874fb72ab7f9eb | |
| parent | d84d541612f67c37a600291c45be31646dbb1e7d (diff) | |
| download | perlweeklychallenge-club-107bdf42f90c5c0d55f7c92cc0959ac54a151244.tar.gz perlweeklychallenge-club-107bdf42f90c5c0d55f7c92cc0959ac54a151244.tar.bz2 perlweeklychallenge-club-107bdf42f90c5c0d55f7c92cc0959ac54a151244.zip | |
Added solutions for w3 c1 (p5 and p6)
| -rw-r--r-- | challenge-003/ruben-westerberg/README | 6 | ||||
| -rwxr-xr-x | challenge-003/ruben-westerberg/perl5/ch-1.pl | 35 | ||||
| -rwxr-xr-x | challenge-003/ruben-westerberg/perl6/ch-1.p6 | 22 |
3 files changed, 61 insertions, 2 deletions
diff --git a/challenge-003/ruben-westerberg/README b/challenge-003/ruben-westerberg/README index 51f17bea4c..c2873957a1 100644 --- a/challenge-003/ruben-westerberg/README +++ b/challenge-003/ruben-westerberg/README @@ -1,5 +1,7 @@ Solution by Ruben Westerberg -Inputs via command line arguments -Challenge 2 (pascal) dies if user supplies less then 3 as input +Challange 1 (5-Smooth p5 and p6) does not require command input and runs indefinately + +Challenge 2 (pascal triangle p5 and p6) dies if user supplies less then 3 as input on the command line + diff --git a/challenge-003/ruben-westerberg/perl5/ch-1.pl b/challenge-003/ruben-westerberg/perl5/ch-1.pl new file mode 100755 index 0000000000..9b7c193e2c --- /dev/null +++ b/challenge-003/ruben-westerberg/perl5/ch-1.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl +# +#Smooth numbersI +my @primes=(2,3,5); +my $power=0; +while (1) { + $power++; + my @smooth=(); + my $t=60**$power; + foreach my $s (1 .. ($t/2)-1) { + foreach my $p (@primes) { + #printf "Prime $p, $s\n"; + my $smooth1=$s*$p; + my $val=$t/$smooth1; + my $test=($t%$smooth1); + if (($test == 0) && ($val >= 2)) { + #printf "smooth: $smooth1, val: $val test: $test\n"; + unless (grep $smooth1 == $_, @smooth) { + push @smooth, $smooth1; + } + unless ( grep $val == $_, @smooth) { + push @smooth, $val; + } + + } + } + } + + printf "5-Smooth numbers for 60^$power\n"; + @smooth=sort { $a <=> $b} @smooth; + foreach (@smooth) { + printf "$_ "; + } + print"\n\n"; +} diff --git a/challenge-003/ruben-westerberg/perl6/ch-1.p6 b/challenge-003/ruben-westerberg/perl6/ch-1.p6 new file mode 100755 index 0000000000..d13a499237 --- /dev/null +++ b/challenge-003/ruben-westerberg/perl6/ch-1.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env perl6 +# +my $powers=(1 ... *) ; +my $primes=(2,3,5); +for $powers<> { + my $smooth=[]; + my $t=60**$_; + for 1..($t/2) -> $s { + append $smooth, + ((do for $primes<> -> $p { + my $smooth1=$s*$p; + my $val=Int($t/$smooth1); + my $test= ($t%%($smooth1)); + ($test && ($val >= 2)) ?? ($smooth1,$val) !! (); + }).flat); + } + say "5-Smooth Numbers for 60^$_: "; + say $smooth.Bag.pairs>>.key.sort.join: " "; + say ""; + sleep 1; + +} |
