Created
July 24, 2012 08:54
project euler 86
This file contains 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 86 : 2012/07/24 | |
;; "Elapsed time: 2840.618843 msecs" | |
(defn is-pethagorean [x y] | |
(let [hypo (Math/sqrt (+ (* x x) (* y y)))] | |
(if (== 0 (rem hypo 1) ) | |
(int hypo) | |
nil))) | |
(defn count-cuboids [a+b c] | |
(+ 1 | |
(- (if (< a+b c) (dec a+b) c) | |
(if (odd? a+b) (/ (inc a+b) 2) (/ a+b 2))))) | |
(defn count-all-cuboids [c] | |
(->> (range 2 (inc (* 2 c))) | |
(filter (partial is-pethagorean c) ,,) | |
(map #(count-cuboids % c) ,,) | |
(reduce + ,,))) | |
(defn pe86 [tacget-count] | |
(loop [cuboids-count 0, max-length 0] | |
(if (> cuboids-count tacget-count) | |
[max-length cuboids-count] | |
(recur (+ cuboids-count | |
(count-all-cuboids (inc max-length))) | |
(inc max-length))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment