Skip to content

Instantly share code, notes, and snippets.

@jedschneider
Created June 28, 2010 22:46
Show Gist options
  • Save jedschneider/456486 to your computer and use it in GitHub Desktop.
Save jedschneider/456486 to your computer and use it in GitHub Desktop.
; sums the number between 1 and 999 that are multiples of 3 or 5
(reduce + (filter #(= 0 (* (rem % 3) (rem % 5))) (take 999 (iterate inc 1))))
@gfredericks
Copy link

Of course that just works cause of a math trick. Now that I think about it, I think the more programming-languages way of drying it up would be
to replace

#(or (= 0 (rem % 3)) (= 0 (rem % 5)))

with

(fn [n](any? #%28= 0 %28rem n %%29%29 [3 5]))

This violates two of the rules you just sent me ;-)

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