aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-06-14 21:15:44 +0100
committerGitHub <noreply@github.com>2022-06-14 21:15:44 +0100
commit9f829447426710a7e62cf875f8c3c7a03d256dfd (patch)
tree95f8d26d1d8f05ae811a8aa5fb7a7f30ae8ddb74
parent07483b8798bee31cee815a89e7a54b0850871a02 (diff)
parenta1b3e5616c1ceb4c7089234befc8562fe4c7c601 (diff)
downloadperlweeklychallenge-club-9f829447426710a7e62cf875f8c3c7a03d256dfd.tar.gz
perlweeklychallenge-club-9f829447426710a7e62cf875f8c3c7a03d256dfd.tar.bz2
perlweeklychallenge-club-9f829447426710a7e62cf875f8c3c7a03d256dfd.zip
Merge pull request #6265 from steve-g-lynn/branch-for-challenge-169
added julia
-rwxr-xr-xchallenge-169/steve-g-lynn/julia/ch-1.jl27
-rwxr-xr-xchallenge-169/steve-g-lynn/julia/ch-2.jl41
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-169/steve-g-lynn/julia/ch-1.jl b/challenge-169/steve-g-lynn/julia/ch-1.jl
new file mode 100755
index 0000000000..2834b080c9
--- /dev/null
+++ b/challenge-169/steve-g-lynn/julia/ch-1.jl
@@ -0,0 +1,27 @@
+#!/usr/bin/julia
+
+using Primes
+using IterTools
+
+brilliant=[]
+
+
+#-- produce a vector of all products of items in an input vector
+#-- (such as a vector of primes)
+
+function myprods(a)
+ retval=[]
+ for i in product(a,a) #-- cartesian product i=(a[j],a[k])
+ retval=[retval; prod(i)] #-- product of the pair in i
+ end
+ return retval
+end
+
+brilliant=[brilliant; myprods(primes(10)); myprods(primes(11,99))]
+
+#-- primes(10): 1-digit primes; primes(11,99): 2-digit primes
+
+brilliant=sort(unique(brilliant))[1:20]
+
+println(brilliant)
+
diff --git a/challenge-169/steve-g-lynn/julia/ch-2.jl b/challenge-169/steve-g-lynn/julia/ch-2.jl
new file mode 100755
index 0000000000..597f73d83c
--- /dev/null
+++ b/challenge-169/steve-g-lynn/julia/ch-2.jl
@@ -0,0 +1,41 @@
+#!/usr/bin/julia
+
+using Primes
+
+ctr=1;
+
+for i in (2:2000)
+ Freq=values(factor(Dict,i))
+
+ # julia stores the factors as a hash-like object of the form
+ # factor{frequency} in perl notation (coerced to regular
+ # julia hash aka Dict here)
+ # values(..) retrieves the values in the key-value pairs
+ # (number of times each factor is repeated)
+
+ #-- skip if only one factor
+ if (length(Freq)==1)
+ continue
+ end
+
+ #-- skip if any factor occurs less than twice
+ if ((Freq .< 2)!=zeros(length(Freq)))
+ continue # next
+ end
+
+ #-- achilles' heel: gcd of Freq should be 1; skip otherwise
+ if (gcd(Freq .+ 0) > 1) # .+ 0 to coerce Freq to array
+ continue
+ end
+
+ print("$i ")
+ global ctr=ctr+1
+
+ if (ctr > 20)
+ break
+ end
+ end
+
+println("")
+
+