How about:
(->> (map * (cycle [1 -1]) (range 1 n))
(reduce +))
?
Dave
On Thu, Nov 13, 2014 at 5:31 PM, Andy L <[email protected]> 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.
>
--
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.