Problem 7
Ruby
1counter = 0;
2num = 1;
3loop do
4 prime = true;
5 temp = 2;
6 while temp <= Math.sqrt(num)
7 if num % temp == 0
8 prime = false;
9 break;
10 end
11 temp += 1;
12 end
13 if prime == true
14 counter += 1;
15 end
16 if counter == 10002
17 break;
18 end
19 num += 1;
20end
21puts"#{num}";
Clojure
1(ns problem7.core)
2
3(defn is-prime?
4 [x]
5 (if (= x 0) false
6 (loop [iter 2 top (int (Math/sqrt x))]
7 (if (> iter top)
8 true
9 (if (= 0 (mod x iter))
10 false
11(recur (inc iter) top))))))
12
13(defn -main
14 []
15 (println (nth (filter is-prime? (range)) 10001)))