Created
March 20, 2010 23:31
-
-
Save hroi/338973 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ; 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