Skip to content

Instantly share code, notes, and snippets.

@johnwalker
Created November 9, 2013 02:16
Show Gist options
  • Save johnwalker/7380708 to your computer and use it in GitHub Desktop.
Save johnwalker/7380708 to your computer and use it in GitHub Desktop.
#12
(ns highly-divisible-triangle-numbers
(:require [clojure.core.reducers :as r]))
(def triangles (reduce
(fn [x y]
(conj x (+ (peek x) y)))
[0]
(range 1 20000)))
(defn factors [n]
(into (sorted-set)
(reduce concat
(for [x (range 1 (inc (Math/sqrt n))) :when (zero? (rem n x))]
[x (/ n x)]))))
(doseq [sol (filter #(> (count (factors %)) 500) triangles)]
(println sol))
(count (factors 76576500))
@johnwalker
Copy link
Author

I kind of stole the factoring code though. But really. I've written enough of those to know that I don't want to write them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment