apfelmus wrote:
I mean, contemplate this trivial exercise for a moment: write a program
> that reads from stdin a series of numbers (one number per line), and
> writes out the sum of the last n numbers. This is a trivial problem,
> and I have no doubt that someone who knows Haskell better than I will
> reply to this email with a single line of code that does it.
Sorry, I can't resist :)
main n = print . sum . map read . take n . reverse . lines =<< getContents
Could someone describe succinctly how to compute the space complexity of
this program, if there are m lines of input and m >> n? Many thanks. --PR
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe