Skip to content

Instantly share code, notes, and snippets.

@shayelkin
Last active November 23, 2018 20:30
Show Gist options
  • Save shayelkin/29711f9306df183bd745a56644860958 to your computer and use it in GitHub Desktop.
Save shayelkin/29711f9306df183bd745a56644860958 to your computer and use it in GitHub Desktop.
Ratio of non primes naturals <100 that only have primary divisors
;; https://twitter.com/sartanbegavhaum/status/1066051737650429952
(defn non-trivial-factors [n]
(filter #(zero? (mod n %)) (range 2 n)))
(def prime? (comp empty? non-trivial-factors))
(defn tomer-number? [n]
(when-let [facts (seq (non-trivial-factors n))]
(every? prime? facts)))
(/ (count (filter tomer-number? (range 2 100)))
(count (remove prime? (range 2 100))))
;; => 34/73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment