Is this cheating?
(defn altsum [n]
(int (* (if (even? (inc n)) 1 -1)
(Math/floor (/ (inc n) 2)))))
On Friday, November 14, 2014 3:31:38 AM UTC+2, Andy L wrote:
>
> Hi,
>
> All I was able to come up with was this
>
> (defn altsum[n] (reduce + (map * (range 1 (inc n)) (interpose -1 (repeat
> 1)))))
>
> ... works quite well, however I was wondering if there is more idiomatic
> way to write that.
>
> Thanks,
> Andy
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.