aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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("")
+
+