Skip to content

Instantly share code, notes, and snippets.

@metric-space
Created August 31, 2016 06:39
Show Gist options
  • Save metric-space/1c23e6ab37f4f319e7e7b73c52b7f828 to your computer and use it in GitHub Desktop.
Save metric-space/1c23e6ab37f4f319e7e7b73c52b7f828 to your computer and use it in GitHub Desktop.
generate sum of odd number squares that are less than 10000
;; 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