Created
June 10, 2010 14:50
-
-
Save bhenry/433107 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 14 | |
(defn do-to-odd [x] | |
(+ 1 (* 3 x))) | |
(defn do-to-even [x] | |
(/ x 2)) | |
(defn get-next [x] | |
(if (zero? (mod x 2)) | |
(do-to-even x) | |
(do-to-odd x))) | |
(defn get-sequence [start] | |
(if (= 1 start) | |
1 | |
[start (get-sequence (get-next start))])) | |
(defn get-seq-length [start] | |
(count (flatten (get-sequence start)))) | |
(defn get-max-vec [v1 v2] | |
(if (pos? (compare (second v1) (second v2))) | |
v1 | |
v2)) | |
(reduce get-max-vec (for [x (range 1 1000000)] | |
[x (get-seq-length x)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment