[Haskell-cafe] Re: On the verge of ... giving up!
Prabhakar Ragde
plragde at uwaterloo.ca
Sun Oct 14 15:33:03 EDT 2007
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
More information about the Haskell-Cafe
mailing list