[ create a new paste ] login | about

Link: http://codepad.org/PblzqC98    [ raw code | output | fork | 1 comment ]

mohit_at_codepad - Haskell, pasted on Mar 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- Written by Mohit Jain
module Main where

baseBall = throwBalls 0 0
throwBalls _ _ [] = []
throwBalls 2 b ('f':r) = ("f: 2 " ++ show b) : throwBalls 2 b r
throwBalls s b ('f':r) = ("f: " ++ (show $ succ s) ++ " " ++ show b) : throwBalls (succ s) b r
throwBalls 2 b ('s':r) = "s: Struck Out." : throwBalls 0 0 r
throwBalls s b ('s':r) = ("s: " ++ (show $ succ s) ++ " " ++ show b) : throwBalls (succ s) b r
throwBalls s 3 ('b':r) = "b: Walk." : throwBalls 0 0 r
throwBalls s b ('b':r) = ( "b: " ++ show s ++ " " ++ (show $ succ b) ) : throwBalls s (succ b) r


main = putStrLn $ unlines $ baseBall "bsbsbsbsffbffbbbsbbsfs"


Output:
b: 0 1
s: 1 1
b: 1 2
s: 2 2
b: 2 3
s: Struck Out.
b: 0 1
s: 1 1
f: 2 1
f: 2 1
b: 2 2
f: 2 2
f: 2 2
b: 2 3
b: Walk.
b: 0 1
s: 1 1
b: 1 2
b: 1 3
s: 2 3
f: 2 3
s: Struck Out.



Create a new paste based on this one


Comments:
posted by mohit_at_codepad on Mar 20
Review Comments:
1. [$] are noisy. Prefer [.] over them wherever possible.
2. Many parenthesis can be avoided by introducing local functions. (using where)
reply