My Weblog

Blog about programming and math

SPOJ 378. Size Contest

SPOJ 378. Size Contest is challenge problem and i could come up with 63 characters long solution which is 10 characters more than best solution in Haskell . Hope i can reduce it further . If you have shorter solution then please let me know.

main =  interact $ show . f .map read . lines  
f (x:l) =  sum . filter (>0) .take x  $  l

May 31, 2011 - Posted by | Programming | ,

1 Comment »

  1. Hello! I can give you some clues which may help you to improve your solution further.
    1. List comprehensions are often shorter than fiter and map.
    2. You can earn one byte. a.b.c$d === a.b$c d, but spaces do not count, so it’s a win.
    3. Instead of filtering, think about simple function which returns 0 for negative numbers and does not change positive numbers.

    Comment by artyomkazak | June 8, 2011 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: