On 6/25/06, Christian Neukirchen <chneukirchen / gmail.com> wrote:

> Given this, I can't resist but "break the rules" even further---by not
> even writing the solution in Ruby. ;-)  It's pretty nice to do in Haskell:
>
> > pascal = iterate (\last -> zipWith (+) ([0] ++ last) (last ++ [0])) [1]
> >
> > pp n = mapM_ (putStrLn . join "|" . map (show)) $ take n $ pascal
> >     where join s (x:xs) | xs == []  = x
> >                         | otherwise = x ++ s ++ join s xs
> >
> > main = pp 666

Muhuhaha.  Would it be too horrible to say that I like the common lisp version?

    (defun pascal (n &optional (op (constantly t)))
      (labels
          ((compute (row n fn)
             (if (= n 0)
                 row
                 (let* ((head (cons 0 row))
                        (tail (reverse head))
                        (next (mapcar #'+ head tail)))
                   (funcall fn next)
                   (compute next (- n 1) fn)))))
        (let ((p0 '(1)))
          (funcall op p0)
          (compute p0 n op))))

Feel free to pass a pretty printer as the second arg ;-)  Oh, and it's
runs pretty briskly for me on cmucl.



-- 
Lou.