Created
August 31, 2016 06:39
-
-
Save metric-space/1c23e6ab37f4f319e7e7b73c52b7f828 to your computer and use it in GitHub Desktop.
generate sum of odd number squares that are less than 10000
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
;; http://learnyouahaskell.com/higher-order-functions | |
;; answer -> 1666500 | |
(let [coll (iterate (partial + 2) 1) | |
sq (fn [x] (* x x))] | |
(reduce (fn [a,x] (if (> (sq x) 10000) (reduced a) (+ a (sq x)))) | |
coll)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment