Skip to content

Instantly share code, notes, and snippets.

@oliverholworthy
Created April 10, 2014 20:40
Show Gist options
  • Save oliverholworthy/10421159 to your computer and use it in GitHub Desktop.
Save oliverholworthy/10421159 to your computer and use it in GitHub Desktop.
Distinct terms in a multiplication table
;; Project Euler
;;
;; Problem 466
;; https://projecteuler.net/problem=466
;; Find P(64,10e16)
(defn distinct-mult [a b]
(loop [sol #{}
n 0
x (range 1 (inc b))
y (range 1 (inc a))]
(if (seq x)
(recur (apply conj sol (map #(* % (first x)) y))
(inc n)
(rest x)
y)
sol)))
(time
(count (distinct-mult 32 1e3)))
;; "Elapsed time: 20.41 msecs"
;; => 13990
(time
(count (distinct-mult 32 1e4)))
;; "Elapsed time: 385.757 msecs"
;; => 138129
(time
(count (distinct-mult 32 1e5)))
;; "Elapsed time: 4455.01 msecs"
;; => 1382819
(time
(count (distinct-mult 32 1e6)))
;; "Elapsed time: 79980.211 msecs"
;; => 13826337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment