Another option is:

((fn pascal ([n] (pascal n [1M])) ([n row] (if (= n 1) row (recur (dec n) (mapv 
(partial reduce +) (partition 2 1 (cons 0 (conj row 0)))))))) 500)

Because row is a vector you can conj 0 to the end (quickly) and cons 0 to the 
front (quickly) and then mapv makes sure you get a vector back.

Sean

On Feb 4, 2014, at 2:39 AM, Andy Smith <the4thamig...@googlemail.com> wrote:

> Ok thanks, thats really helpful. The second link suggests using doall, which 
> seems to do the trick :
> 
> ((fn pascal ([n] (pascal n [1M])) ([n row] (if (= n 1) row (recur (dec n) 
> (map (partial reduce +) (doall (partition 2 1 (concat [0] row [0])))))))) 500)
> 
> However you do lose the laziness, but here the laziness is not needed ...
> 


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to