Commits

Lars Yencken committed 5d051a8

Julia 06-07.

  • Participants
  • Parent commits 5b62fbd

Comments (0)

Files changed (2)

File julia/06-sum-squares.jl

+#!/usr/bin/env julia
+#
+#  06-sum-square-difference.jl
+#  euler
+#
+#  Find the difference between the sum of squares and the square of the sum
+#  of the first hundred natural numbers.
+#
+
+println(sum(1:100)^2 - sum([i^2 for i = 1:100]))

File julia/07-prime.jl

+#!/usr/bin/env julia
+#
+#  07-prime.jl
+#  euler
+#
+#  What is the 10001st prime number?
+#
+
+function primes(n)
+    p = Int64[2, 3, 5, 7]
+    next = 8
+    while length(p) < n
+        isprime = true
+        for f in p
+            if next % f == 0
+                isprime = false
+                break
+            end
+        end
+        if isprime
+            push!(p, next)
+        end
+        next += 1
+    end
+
+    p
+end
+
+println(primes(10001)[end])