Last active
April 5, 2016 14:38
-
-
Save Arnauld/f517059ea2e0482ed216e0da349484ed to your computer and use it in GitHub Desktop.
(prime-numbers.core/breaz (* 25 1000000))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns prime-numbers.core) | |
; http://clj-me.cgrand.net/2009/07/30/everybody-loves-the-sieve-of-eratosthenes/ | |
(defn primes3 [max] | |
(let [enqueue (fn [sieve n factor] | |
(let [m (+ n (+ factor factor))] | |
(if (sieve m) | |
(recur sieve m factor) | |
(assoc sieve m factor)))) | |
next-sieve (fn [sieve candidate] | |
(if-let [factor (sieve candidate)] | |
(-> sieve | |
(dissoc candidate) | |
(enqueue candidate factor)) | |
(enqueue sieve candidate candidate)))] | |
(cons 2 (vals (reduce next-sieve {} (range 3 max 2)))))) | |
(defn keep-next [filter-fn list] | |
(let [[_ xs] (reduce (fn [[p ys] e] | |
(if (filter-fn p) | |
[e (conj ys e)] | |
[e ys])) | |
[(first list) []] | |
(drop 1 list))] | |
xs)) | |
(defn breaz [max] | |
(let [freqs (->> (sort (primes3 max)) | |
(keep-next #(= 9 (mod % 10))) | |
(map #(mod % 10)) | |
(frequencies)) | |
total (reduce (fn [acc [_ v]] (+ acc v)) 0 freqs) | |
probas (map (fn [[k v]] | |
[k (float (* 100 (/ v total)))]) freqs)] | |
(println ">" freqs) | |
(println ">" total) | |
(println ">" probas) | |
(doseq [[k v] (sort-by (fn [[k _]] k) probas)] | |
(println k ":" (format "%.2f" v))))) |
Author
Arnauld
commented
Apr 5, 2016
The news
Most mathematicians would have assumed that a prime should have an equal chance of being followed by a prime ending in 1, 3, 7 or 9. But the problem is: “Among the first billion prime numbers, for instance, a prime ending in 9 is almost 65 percent more likely to be followed by a prime ending in 1 than another prime ending in 9.” Prime numbers wouldn’t be distributed evenly and randomly…
Think that's cool? Let's play!
Give us the probability for a prime number ending by 9 to be followed by a prime ending by 1 / 3 / 7 / 9. Only consider here numbers lesser than 25*10^6.
Be among the first three people to send us the right answer at talent@breaz.io
and win a goodies pack (Hired branded t-shirt, mug and sunglasses)!
Game starts now!
Information source: Quanta Magazine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment