Hacker Newsnew | past | comments | ask | show | jobs | submit | passed_By's commentslogin

So, haskell version may be little shorter

  main = interact $ unlines. map (show.calc) .lines

  calc :: String -> [Float]
  calc = foldl f [] . words
    where 
      f (x:y:zs) "+" = (y + x):zs
      f (x:y:zs) "-" = (y - x):zs
      f (x:y:zs) "*" = (y * x):zs
      f (x:y:zs) "/" = (y / x):zs
      f xs y         = read y : xs


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: