Skip to content

Instantly share code, notes, and snippets.

@hroi
Created March 20, 2010 23:31
Show Gist options
  • Select an option

  • Save hroi/338973 to your computer and use it in GitHub Desktop.

Select an option

Save hroi/338973 to your computer and use it in GitHub Desktop.
; Problem 12
;
; What is the value of the first triangle number to have over five hundred divisors?
;
(def natnums (iterate inc 1))
(def trinums (lazy-cat [(first natnums)] (map + trinums (rest natnums))))
(defn divcount [n]
(* 2 (count
(for [x (range 1 (Math/sqrt n))
:when (zero? (rem n x))] x))))
(defn answer [n]
(first (filter #(> (divcount %) n) trinums)))
; => 76576500 (575 divisors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment