Skip to content

Instantly share code, notes, and snippets.

@jedschneider
Created June 28, 2010 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

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

can be reduced to

(= 0 (* (rem % 3) (rem % 5)))

but only because math is cool.

@jedschneider
Copy link
Author

agreed, this is a good change and dries up the code. I was looking for a way to get rid of the duplicate declaration.

@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