aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-145/pokgopun/README1
-rw-r--r--challenge-145/pokgopun/go/ch-1.go53
-rw-r--r--challenge-145/pokgopun/go/ch-2.go84
-rw-r--r--challenge-146/pokgopun/go/ch-2.go35
-rw-r--r--challenge-168/julien-fiegehenn/perl/ch-1.pl48
-rw-r--r--challenge-168/julien-fiegehenn/perl/ch-2.pl78
-rw-r--r--challenge-168/lubos-kolouch/perl/ch-1.pl33
-rw-r--r--challenge-168/lubos-kolouch/python/ch-1.py39
-rw-r--r--challenge-168/massa/raku/ch-1.raku2
-rw-r--r--challenge-168/massa/raku/ch-2.raku28
-rw-r--r--challenge-168/roger-bell-west/blog.txt1
-rwxr-xr-xchallenge-168/steve-g-lynn/julia/ch-1.jl29
-rwxr-xr-xchallenge-168/steve-g-lynn/julia/ch-2.jl15
-rwxr-xr-xchallenge-168/steve-g-lynn/perl/ch-1.pl48
-rwxr-xr-xchallenge-168/steve-g-lynn/perl/ch-2.pl37
-rwxr-xr-xchallenge-168/steve-g-lynn/raku/ch-1.p637
-rwxr-xr-xchallenge-168/steve-g-lynn/raku/ch-2.p684
-rw-r--r--stats/pwc-current.json193
-rw-r--r--stats/pwc-language-breakdown-summary.json74
-rw-r--r--stats/pwc-language-breakdown.json1188
-rw-r--r--stats/pwc-leaders.json742
-rw-r--r--stats/pwc-summary-1-30.json116
-rw-r--r--stats/pwc-summary-121-150.json36
-rw-r--r--stats/pwc-summary-151-180.json122
-rw-r--r--stats/pwc-summary-181-210.json106
-rw-r--r--stats/pwc-summary-211-240.json64
-rw-r--r--stats/pwc-summary-241-270.json80
-rw-r--r--stats/pwc-summary-31-60.json116
-rw-r--r--stats/pwc-summary-61-90.json56
-rw-r--r--stats/pwc-summary-91-120.json106
-rw-r--r--stats/pwc-summary.json48
31 files changed, 2100 insertions, 1599 deletions
diff --git a/challenge-145/pokgopun/README b/challenge-145/pokgopun/README
new file mode 100644
index 0000000000..33dfd303a4
--- /dev/null
+++ b/challenge-145/pokgopun/README
@@ -0,0 +1 @@
+Solution by PokGoPun
diff --git a/challenge-145/pokgopun/go/ch-1.go b/challenge-145/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..d39063d4ef
--- /dev/null
+++ b/challenge-145/pokgopun/go/ch-1.go
@@ -0,0 +1,53 @@
+// You are given 2 arrays of same size, @a and @b.
+// Write a script to implement Dot Product.
+// Usage: go run ch-1.go 1,2,3 4,5,6
+package main
+
+import (
+ "fmt"
+ "log"
+ "os"
+ "strconv"
+ "strings"
+)
+
+func main() {
+ var sample [][]int
+ if len(os.Args) > 2 {
+ m := map[int]struct{}{}
+ for _, v := range os.Args[1:] {
+ strs := strings.Split(v, ",")
+ m[len(strs)] = struct{}{}
+ nums := make([]int, len(strs))
+ for i, v := range strs {
+ n, err := strconv.Atoi(v)
+ if err != nil {
+ log.Fatal(err)
+ }
+ nums[i] = n
+ }
+ sample = append(sample, nums)
+ }
+ if len(m) > 1 {
+ log.Fatal("Arrays are not in the same size")
+ }
+ } else {
+ sample = [][]int{
+ []int{1, 2, 3},
+ []int{4, 5, 6},
+ }
+ }
+ fmt.Println(sample, "=>", dp(sample))
+}
+
+func dp(ss [][]int) (r int) {
+ l := len(ss[0])
+ for i := 0; i < l; i++ {
+ n := 1
+ for j := 0; j < len(ss); j++ {
+ n *= ss[j][i]
+ }
+ r += n
+ }
+ return r
+}
diff --git a/challenge-145/pokgopun/go/ch-2.go b/challenge-145/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..9f75a558ec
--- /dev/null
+++ b/challenge-145/pokgopun/go/ch-2.go
@@ -0,0 +1,84 @@
+// Write a script to create a Palindromic Tree for the given string.
+// All examples do not have a case that a letter happens more than twice in given words but we will handle the case as well
+// Here additional examples for the case: banana, redeemable, deterministic, heterogeneity, initiation, monopolous, honolulu
+package main
+
+import (
+ "fmt"
+ "os"
+ "sort"
+ "strings"
+)
+
+func main() {
+ var sample []string
+ if len(os.Args) > 1 {
+ sample = os.Args[1:]
+ } else {
+ sample = []string{
+ "redivider",
+ "deific",
+ "rotors",
+ "challenge",
+ "champion",
+ "christmas",
+ "banana",
+ "redeemable",
+ "deterministic",
+ "heterogeneity",
+ "initiation",
+ "monopolous",
+ "honolulu",
+ }
+ }
+ for _, v := range sample {
+ p := newPldt(v)
+ fmt.Println(p)
+ }
+}
+
+type pldt struct {
+ word string
+ seen map[string]bool
+ cpos map[byte][]int
+ vals []string
+}
+
+func newPldt(s string) (p pldt) {
+ p.word = s
+ p.seen = make(map[string]bool)
+ p.cpos = make(map[byte][]int)
+ for i, v := range []byte(p.word) {
+ p.cpos[v] = append(p.cpos[v], i)
+ }
+ for _, c := range []byte(p.word) {
+ if p.seen[string(c)] {
+ continue
+ }
+ p.seen[string(c)] = true
+ p.vals = append(p.vals, string(c))
+ for i, pos1 := range p.cpos[c] {
+ for _, pos2 := range p.cpos[c][i+1:] {
+ o := p.word[pos1 : pos2+1]
+ if p.seen[o] {
+ continue
+ }
+ r := []byte(o)
+ sort.SliceStable(r, func(i, j int) bool {
+ return true
+ })
+ if o == string(r) {
+ p.vals = append(p.vals, o)
+ p.seen[o] = true
+ }
+ }
+ }
+ }
+ return p
+}
+
+func (p pldt) String() string {
+ var b strings.Builder
+ b.WriteString("Input: '" + p.word + "'\nOutput: " + strings.Join(p.vals, " ") + "\n")
+ return b.String()
+}
diff --git a/challenge-146/pokgopun/go/ch-2.go b/challenge-146/pokgopun/go/ch-2.go
index b8aea49f0f..a8545314f3 100644
--- a/challenge-146/pokgopun/go/ch-2.go
+++ b/challenge-146/pokgopun/go/ch-2.go
@@ -2,35 +2,22 @@ package main
import (
"fmt"
- "log"
"os"
)
func main() {
- samples := [][2]uint{
- [2]uint{3, 5},
- [2]uint{4, 3},
- }
+ var sample []string
if len(os.Args) > 1 {
- var sample [2]uint
- _, err := fmt.Sscanf(os.Args[1], "%d/%d", &sample[0], &sample[1])
- if err != nil {
- log.Fatal(err)
+ sample = os.Args[1:]
+ } else {
+ sample = []string{
+ "redivider",
+ "deific",
+ "rotors",
+ "challenge",
+ "champion",
+ "christmas",
}
- samples = [][2]uint{sample}
- }
- for _, v := range samples {
- p := parent(v)
- gp := parent(p)
- fmt.Printf("Input: member = '%d/%d'\nOutput: parent ='%d/%d' and grandparent = '%d/%d'\n", v[0], v[1], p[0], p[1], gp[0], gp[1])
- }
-}
-
-func parent(s [2]uint) [2]uint {
- if s[0] > s[1] {
- return [2]uint{s[0] - s[1], s[1]}
- } else if s[0] < s[1] {
- return [2]uint{s[0], s[1] - s[0]}
}
- return [2]uint{1, 1}
+ fmt.Println(sample)
}
diff --git a/challenge-168/julien-fiegehenn/perl/ch-1.pl b/challenge-168/julien-fiegehenn/perl/ch-1.pl
new file mode 100644
index 0000000000..2e331a2415
--- /dev/null
+++ b/challenge-168/julien-fiegehenn/perl/ch-1.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+
+# Task 1: Perrin Prime
+# Submitted by: Roger Bell_West
+# The Perrin sequence is defined to start with [3, 0, 2]; after that, term N is the sum of terms N-2 and N-3. (So it continues 3, 2, 5, 5, 7, ….)
+
+# A Perrin prime is a number in the Perrin sequence which is also a prime number.
+
+# Calculate the first 13 Perrin Primes.
+
+# f(13) = [2, 3, 5, 7, 17, 29, 277, 367, 853, 14197, 43721, 1442968193, 792606555396977]
+
+sub is_prime {
+ my $n = shift;
+ return 0 if $n < 2;
+ return 1 if $n == 2;
+ return 0 if $n % 2 == 0;
+ for (my $i = 3; $i <= sqrt($n); $i += 2) {
+ return 0 if $n % $i == 0;
+ }
+ return 1;
+}
+
+sub perrin_primes {
+ my $n = shift;
+ my %primes = map { $_ => 1 } 2, 3;
+ my @perrin = (3, 0, 2);
+ my $i = 3;
+ while (keys %primes < $n) {
+ $perrin[$i] = $perrin[$i - 2] + $perrin[$i - 3];
+ if (is_prime($perrin[$i])) {
+ $primes{$perrin[$i]} = 1;
+ }
+ $i++;
+ }
+ return sort { $a <=> $b } keys %primes;
+}
+
+my @primes = perrin_primes(13);
+say "@primes";
+
+__END__
+use Test::More;
+is_deeply \@primes, [2, 3, 5, 7, 17, 29, 277, 367, 853, 14197, 43721, 1442968193, 792606555396977];
+done_testing; \ No newline at end of file
diff --git a/challenge-168/julien-fiegehenn/perl/ch-2.pl b/challenge-168/julien-fiegehenn/perl/ch-2.pl
new file mode 100644
index 0000000000..9e9812d039
--- /dev/null
+++ b/challenge-168/julien-fiegehenn/perl/ch-2.pl
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+
+# Task 2: Home Prime
+# Submitted by: Mohammad S Anwar
+# You are given an integer greater than 1.
+
+# Write a script to find the home prime of the given number.
+
+# In number theory, the home prime HP(n) of an integer n greater than 1 is the prime number obtained by repeatedly factoring the increasing concatenation of prime factors including repetitions.
+
+# Further information can be found on Wikipedia and OEIS.
+
+# Example
+# As given in the Wikipedia page,
+
+# HP(10) = 773, as 10 factors as 2×5 yielding HP10(1) = 25, 25 factors as 5×5 yielding HP10(2) = HP25(1) = 55, 55 = 5×11 implies HP10(3) = HP25(2) = HP55(1) = 511, and 511 = 7×73 gives HP10(4) = HP25(3) = HP55(2) = HP511(1) = 773, a prime number.
+
+# written with github copilot
+
+# calculate the prime factors of a number
+sub prime_factors {
+ my $n = shift;
+ my @factors = ();
+ my $i = 2;
+ while ($n > 1) {
+ while ($n % $i == 0) {
+ push @factors, $i;
+ $n /= $i;
+ }
+ $i++;
+ }
+ return @factors;
+}
+
+sub is_prime {
+ my $n = shift;
+ return 0 if $n < 2;
+ return 1 if $n == 2;
+ return 0 if $n % 2 == 0;
+ for (my $i = 3; $i <= sqrt($n); $i += 2) {
+ return 0 if $n % $i == 0;
+ }
+ return 1;
+}
+
+# calculate the home prime of a number
+# In number theory, the home prime HP(n) of an integer n greater than 1 is the prime number obtained by repeatedly factoring the increasing concatenation of prime factors including repetitions.
+sub home_prime {
+ my $n = shift;
+
+ return $n if is_prime($n);
+ return home_prime(join '', prime_factors($n));
+}
+
+# a version of home_prime that produces debug output at every step
+sub home_prime_debug {
+ my $n = shift;
+
+ say "n = $n";
+ return $n if is_prime($n);
+ my @factors = prime_factors($n);
+ say "factors = @factors";
+ return home_prime_debug(join '', @factors);
+}
+
+__END__
+
+use Test::More;
+is_deeply [prime_factors(10)], [2, 5];
+is_deeply [prime_factors(13)], [13];
+is_deeply [prime_factors(14)], [2, 7];
+
+is home_prime(10), 773;
+is home_prime_debug(10), 773;
+done_testing; \ No newline at end of file
diff --git a/challenge-168/lubos-kolouch/perl/ch-1.pl b/challenge-168/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..956d2822e4
--- /dev/null
+++ b/challenge-168/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,33 @@
+package main;
+use strict;
+use warnings;
+use Math::Prime::Util qw(is_prime);
+
+sub generate_perrin_sequence {
+ my $n = shift;
+ my @perrin_sequence = ( 3, 0, 2 );
+
+ my %perrin_primes;
+
+ while ( scalar keys %perrin_primes < $n ) {
+ my $next_number = $perrin_sequence[-3] + $perrin_sequence[-2];
+ push @perrin_sequence, $next_number;
+ $perrin_primes{$next_number} = 1 if is_prime($next_number);
+ }
+
+ my @primes = sort { $a <=> $b } keys %perrin_primes;
+
+ return \@primes;
+}
+
+use Test::More;
+
+is_deeply(
+ generate_perrin_sequence(13),
+ [ 2, 3, 5, 7, 17, 29, 277, 367, 853, 14197, 43721, 1442968193,
+ 792606555396977
+ ]
+);
+
+done_testing;
+1;
diff --git a/challenge-168/lubos-kolouch/python/ch-1.py b/challenge-168/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..8c8790c5dc
--- /dev/null
+++ b/challenge-168/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,39 @@
+""" Challenge 168 Task 1 LK Python """
+
+from sympy import isprime
+
+
+def generate_perrin_primes(n: int) -> list:
+ """
+ Generate all primes up to n using the Perrin sequence.
+ """
+ perrin_sequence = [3, 0, 2]
+
+ perrin_primes: dict = {}
+
+ while len(perrin_primes.keys()) < n:
+
+ next_number = perrin_sequence[-3] + perrin_sequence[-2]
+ perrin_sequence.append(next_number)
+
+ if isprime(next_number):
+ perrin_primes[next_number] = True
+
+ return sorted(perrin_primes.keys())
+
+
+assert generate_perrin_primes(13) == [
+ 2,
+ 3,
+ 5,
+ 7,
+ 17,
+ 29,
+ 277,
+ 367,
+ 853,
+ 14197,
+ 43721,
+ 1442968193,
+ 792606555396977,
+]
diff --git a/challenge-168/massa/raku/ch-1.raku b/challenge-168/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..2fbde00b8c
--- /dev/null
+++ b/challenge-168/massa/raku/ch-1.raku
@@ -0,0 +1,2 @@
+use v6;
+(3, 0, 2, * + * + 0 * * ... *).grep(*.is-prime).unique.head(13).sort.say
diff --git a/challenge-168/massa/raku/ch-2.raku b/challenge-168/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..535eaa16fa
--- /dev/null
+++ b/challenge-168/massa/raku/ch-2.raku
@@ -0,0 +1,28 @@
+use v6;
+
+my sub factors(int \x is copy) {
+ my int $possible-factor = 2;
+ gather {
+ while x > 1 {
+ if $possible-factor.is-prime && x %% $possible-factor {
+ take $possible-factor;
+ x div= $possible-factor
+ } else {
+ Nil until is-prime ++$possible-factor
+ }
+ }
+ }
+}
+
+my sub hp(int \x is copy) {
+ loop {
+ given +[~] factors x {
+ .return if .is-prime;
+ x = $_
+ }
+ }
+}
+
+sub MAIN(Int() \n where * > 1) {
+ say hp n
+}
diff --git a/challenge-168/roger-bell-west/blog.txt b/challenge-168/roger-bell-west/blog.txt
new file mode 100644
index 0000000000..aca56403ca
--- /dev/null
+++ b/challenge-168/roger-bell-west/blog.txt
@@ -0,0 +1 @@
+https://blog.firedrake.org/archive/2022/06/The_Weekly_Challenge_168__At_Home_with_the_Perrins.html
diff --git a/challenge-168/steve-g-lynn/julia/ch-1.jl b/challenge-168/steve-g-lynn/julia/ch-1.jl
new file mode 100755
index 0000000000..e58d43e005
--- /dev/null
+++ b/challenge-168/steve-g-lynn/julia/ch-1.jl
@@ -0,0 +1,29 @@
+#!/usr/bin/julia
+#-- slower than perl or raku for this task because of slow startup
+
+using Primes
+
+function perrin(n::Int64)
+ return ( ([0 1 0; 0 0 1; 1 1 0]^n)*[3;0;2] )[1];
+end
+
+savedprimes=Array{Int64}(undef,13)
+savedprimes[1]=2; savedprimes[2]=3;savedprimes[3]=5;savedprimes[4]=7
+ctr=3;
+
+for n in (6:1000)
+ perrinval=perrin(n)
+ if (isprime(perrinval) && (ctr <=13))
+ savedprimes[ctr]=perrinval
+ global ctr=ctr+1
+ end
+end
+
+print("(")
+for n in (1:13)
+ print(savedprimes[n])
+ print(" ")
+end
+print(")\n")
+
+
diff --git a/challenge-168/steve-g-lynn/julia/ch-2.jl b/challenge-168/steve-g-lynn/julia/ch-2.jl
new file mode 100755
index 0000000000..19d4c7d498
--- /dev/null
+++ b/challenge-168/steve-g-lynn/julia/ch-2.jl
@@ -0,0 +1,15 @@
+#! /usr/bin/julia
+
+using Primes
+
+function homeprime(n::Int64)
+ ncopy=n
+ while (!isprime(ncopy))
+ ncopy=parse(Int64,join(factor(Vector,ncopy)))
+ end
+ return ncopy
+end
+
+println(homeprime(16))
+#31636373
+
diff --git a/challenge-168/steve-g-lynn/perl/ch-1.pl b/challenge-168/steve-g-lynn/perl/ch-1.pl
index a8729418aa..35818da7f9 100755
--- a/challenge-168/steve-g-lynn/perl/ch-1.pl
+++ b/challenge-168/steve-g-lynn/perl/ch-1.pl
@@ -3,8 +3,11 @@
use Math::Prime::XS qw(is_prime);
local %saveprimes=();
-for (0..150) {
- local $chk=&perrin($_);
+local @perrin=(3,0,2);
+for (1..150) {
+ local $chk=$perrin[0];
+ push @perrin, $perrin[0]+$perrin[1];
+ shift @perrin;
(is_prime($chk)) && ($saveprimes{$chk}=1);
@saveprimes==26 && last;
}
@@ -15,45 +18,4 @@ foreach (sort{$a<=>$b} keys %saveprimes){
}
print ")\n";
-#-- subs
-
-sub perrin {
- local ($n)=@_;
-
- if ($n==0) { return 3 }
- else { return &postmult_302(&matpow($n)) }
-}
-
-#-- subs for fast computation of perrin number using matrix formula
-#-- see wikipedia https://en.wikipedia.org/wiki/Perrin_number
-
-#-- [0 1 0; 0 0 1; 1 1 0]^n (only need 1st row)
-sub matpow {
- local ($n)=@_;
-
- if ($n==1) { return (0,1,0) }
- else {return &postmult_010_001_110(&matpow($n-1))}
-}
-
-
-# 3x3 matrix * [0 1 0; 0 0 1; 1 1 0] (retain 1st row of product)
-sub postmult_010_001_110 {
- # [a11 a12 a13; a21 a22 a23; a31 a32 a33]*[0 1 0; 0 0 1; 1 1 0]
- local ($a11,$a12,$a13)=@_; #just need 1st row
-
- local $b11=$a13;
- local $b12=$a11+$a13;
- local $b13=$a12;
-
- return ($b11,$b12,$b13) #-- return just 1st row
-}
-
-# 3x3 matrix * [3;0;2] retain 1st element of product
-sub postmult_302 {
- local ($a11,$a12,$a13)=@_; #-- just need 1st row
- # [a11 a12 a13; a21 a22 a23; a31 a32 a33]*[3;0;2]
- #
- return $a11*3+$a13*2; #-- 1st element
-
-}
diff --git a/challenge-168/steve-g-lynn/perl/ch-2.pl b/challenge-168/steve-g-lynn/perl/ch-2.pl
new file mode 100755
index 0000000000..d1f6f0aced
--- /dev/null
+++ b/challenge-168/steve-g-lynn/perl/ch-2.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use Math::Prime::XS qw(is_prime sieve_primes);
+
+
+print &home_prime(16),"\n";
+#-- should be 31636373 [wikipedia example]
+
+sub home_prime {
+ local ($n)=@_;
+ while (1){
+ $n=&factors($n);
+ (is_prime($n)) && last;
+ }
+ return $n;
+}
+
+
+sub factors {
+ #--return concatenated prime factors of a number n
+ local ($n)=@_;
+ local @primes=sieve_primes($n);
+ local $retstring="";
+
+ if (is_prime($n)){
+ return $n;
+ }
+ else {
+ foreach $prime (sort{$a<=>$b} @primes){
+ while ( ($n % $prime) == 0){
+ $n /= $prime;
+ $retstring .= $prime;
+ }
+ }
+ }
+ return $retstring;
+}
diff --git a/challenge-168/steve-g-lynn/raku/ch-1.p6 b/challenge-168/steve-g-lynn/raku/ch-1.p6
index ace5c647e1..9610889cf2 100755
--- a/challenge-168/steve-g-lynn/raku/ch-1.p6
+++ b/challenge-168/steve-g-lynn/raku/ch-1.p6
@@ -1,8 +1,11 @@
#!/usr/bin/raku
my %saveprimes=();
+my ($p1,$p2,$p3)=(3,0,2);
for ^Inf {
- my $chk=perrin($_);
+ my $chk=$p1;
+ my $p4=$p1+$p2;
+ $p1=$p2; $p2=$p3;$p3=$p4;
(is-prime($chk)) && (%saveprimes{$chk}=1);
%saveprimes.elems==13 && last;
}
@@ -10,36 +13,4 @@ for ^Inf {
say %saveprimes.keys.sort({.Int});
-#-- subs
-multi sub perrin(0) {3}
-multi sub perrin(Int $n where ($n>0)){postmult_302(matpow($n))}
-
-#-- subs for fast computation of perrin number using matrix formula
-#-- see wikipedia https://en.wikipedia.org/wiki/Perrin_number
-
-#[0 1 0; 0 0 1; 1 1 0]^n (retain 1st row)
-multi sub matpow(1){ (0,1,0) }
-multi sub matpow(Int $n where ($n>1)) { postmult_010_001_110 (matpow($n-1)) }
-
-# 3x3 matrix * [0 1 0; 0 0 1; 1 1 0] (retain 1st row of product)
-sub postmult_010_001_110 (*@inmatrix){
- # [a11 a12 a13; a21 a22 a23; a31 a32 a33]*[0 1 0; 0 0 1; 1 1 0]
- my ($a11,$a12,$a13)=@inmatrix; #just need 1st row
-
- my $b11=$a13;
- my $b12=$a11+$a13;
- my $b13=$a12;
-
- return ($b11,$b12,$b13) #-- return just 1st row
-}
-
-# 3x3 matrix * [3;0;2] retain 1st element of product
-sub postmult_302 (*@inmatrix){
- my ($a11,$a12,$a13)=@inmatrix; #-- just need 1st row
- # [a11 a12 a13; a21 a22 a23; a31 a32 a33]*[3;0;2]
- #
- my $b1=$a11*3+$a13*2; #-- 1st element
-
- return $b1;
-}
diff --git a/challenge-168/steve-g-lynn/raku/ch-2.p6 b/challenge-168/steve-g-lynn/raku/ch-2.p6
new file mode 100755
index 0000000000..b4183fd6d3
--- /dev/null
+++ b/challenge-168/steve-g-lynn/raku/ch-2.p6
@@ -0,0 +1,84 @@
+#!/usr/bin/raku
+
+say homeprime(16);
+# 31636373
+#-- works but slow
+
+#-- sub for home prime
+
+sub homeprime(Int $n){
+ my $ncopy=$n;
+ while (1) {
+ $ncopy=factor($ncopy).Int;
+ ($ncopy.is-prime) && last;
+ }
+ return $ncopy;
+}
+
+#--sub for factorizing
+
+multi sub factor (1) {1}
+
+multi sub factor (Int $n where $n > 1){
+#-- returns string concatenation of prime factors
+# my @primes=prime_sieve($n);
+ my @primes=find_primes($n);
+ my $retstring="";
+ my $ncopy=$n;
+
+ ($n.is-prime) && (return $n);
+
+ for @primes -> $prime {
+ while ( ($ncopy % $prime)==0) {
+ $ncopy /= $prime;
+ $retstring ~= $prime;
+ }
+ }
+ return $retstring;
+}
+
+multi sub find_primes(Int $n where $n <= 13) {
+ my @primes=(2,3,5,7,11,13);
+ my @retval=();
+ for @primes -> $prime {
+ ($prime < $n) && (push @retval, $prime);
+ }
+ return (@retval.sort);
+}
+
+multi sub find_primes(Int $n where $n > 13) {
+#-- naive approach by trial factorization
+ my @primes=(3,7,11,13);
+
+ my $i=13;
+
+ while ($i < $n) {
+ #-- count only odd numbers not ending in 5. Take 4 at a time.
+ my @testarray=();
+
+ (($i+4) < $n) && (push @testarray, ($i+4));
+ (($i+6) < $n) && (push @testarray, ($i+6));
+ (($i+8) < $n) && (push @testarray, ($i+8));
+ (($i+10) < $n) && (push @testarray, ($i+10));
+
+ while (@testarray.elems > 0) {
+ my $testitem=shift(@testarray);
+ unless ((($testitem % 6)==1) || (($testitem % 6)==5)) {
+ #-- use the property that prime numbers above 5 are 6k+1 or 6k-1
+ next;
+ }
+ for @primes -> $prime {
+ ($prime > sqrt($testitem)) && last;
+ (($testitem % $prime)==0) && last;
+ }
+ push @primes, $testitem;
+ }
+ $i += 10;
+ }
+
+ splice(@primes,0,1, <2 3 5>); #-- left out 2 and 5 earlier to avoid
+ # unnecessary redundant factorizing
+ return (@primes.sort);
+}
+
+
diff --git a/stats/pwc-current.json b/stats/pwc-current.json
index 59d88c2320..bd43401c7c 100644
--- a/stats/pwc-current.json
+++ b/stats/pwc-current.json
@@ -1,32 +1,28 @@
{
- "plotOptions" : {
- "series" : {
- "borderWidth" : 0,
- "dataLabels" : {
- "format" : "{point.y}",
- "enabled" : 1
- }
- }
- },
- "legend" : {
- "enabled" : 0
- },
- "chart" : {
- "type" : "column"
- },
"drilldown" : {
"series" : [
{
- "name" : "E. Choroba",
- "id" : "E. Choroba",
"data" : [
[
"Perl",
2
]
+ ],
+ "id" : "E. Choroba",
+ "name" : "E. Choroba"
+ },
+ {
+ "id" : "Humberto Massa",
+ "name" : "Humberto Massa",
+ "data" : [
+ [
+ "Raku",
+ 2
+ ]
]
},
{
+ "id" : "James Smith",
"name" : "James Smith",
"data" : [
[
@@ -37,11 +33,31 @@
"Blog",
1
]
+ ]
+ },
+ {
+ "name" : "Julien Fiegehenn",
+ "id" : "Julien Fiegehenn",
+ "data" : [
+ [
+ "Perl",
+ 2
+ ]
+ ]
+ },
+ {
+ "data" : [
+ [
+ "Perl",
+ 1
+ ]
],
- "id" : "James Smith"
+ "id" : "Lubos Kolouch",
+ "name" : "Lubos Kolouch"
},
{
"name" : "Luca Ferrari",
+ "id" : "Luca Ferrari",
"data" : [
[
"Raku",
@@ -51,12 +67,11 @@
"Blog",
6
]
- ],
- "id" : "Luca Ferrari"
+ ]
},
{
- "name" : "Mark Anderson",
"id" : "Mark Anderson",
+ "name" : "Mark Anderson",
"data" : [
[
"Raku",
@@ -75,7 +90,6 @@
]
},
{
- "id" : "Peter Campbell Smith",
"data" : [
[
"Perl",
@@ -86,9 +100,12 @@
1
]
],
+ "id" : "Peter Campbell Smith",
"name" : "Peter Campbell Smith"
},
{
+ "id" : "Robert DiCicco",
+ "name" : "Robert DiCicco",
"data" : [
[
"Perl",
@@ -98,9 +115,7 @@
"Raku",
2
]
- ],
- "id" : "Robert DiCicco",
- "name" : "Robert DiCicco"
+ ]
},
{
"name" : "Roger Bell_West",
@@ -113,10 +128,15 @@
[
"Raku",
2
+ ],
+ [
+ "Blog",
+ 1
]
]
},
{
+ "name" : "Ryan Thompson",
"id" : "Ryan Thompson",
"data" : [
[
@@ -131,24 +151,25 @@
"Blog",
2
]
- ],
- "name" : "Ryan Thompson"
+ ]
},
{
+ "name" : "Stephen G Lynn",
+ "id" : "Stephen G Lynn",
"data" : [
[
"Perl",
- 1
+ 2
],
[
"Raku",
- 1
+ 2
]
- ],
- "id" : "Stephen G Lynn",
- "name" : "Stephen G Lynn"
+ ]
},
{
+ "name" : "W. Luis Mochan",
+ "id" : "W. Luis Mochan",
"data" : [
[
"Perl",
@@ -158,29 +179,77 @@
"Blog",
1
]
- ],
- "id" : "W. Luis Mochan",
- "name" : "W. Luis Mochan"