Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Haskell I/O Functions

Hello.
What i want to do it's a program that when i write couple of lines with 2 numbers each (games results) like :

1 4
1 1
3 1
3 3
2 1
4 0

it gives

2 (number of games untill victory)

or

1 4
2 3
2 2

it gives

didn't win yet

what i've done is

gamesUntillVictory :: IO ()
gamesUntillVictory =
do
text <- getContents
let
xss :: [String]
xss = lines text
xsss :: [[String]]
xsss = [words x | x <- xss]
yss :: [(Int,Int)]
yss = [toEvens y | y <- xsss]
if ( games yss == length yss)
then
putStrLn "didn't win yet"
else
putStrLn (show (games yss))


toEvens :: [String] -> (Int,Int)
toEvens xs = (read (head xs), read (last xs))

games :: [(Int,Int)] -> Int
games [] = 0
games ((k,v):ys)
| k > v = 0
| otherwise = 1 + games ys

and i always get an error that i can't fix.
I would like to know what i did wrong and a possible solution for this problem. Please notice that i've been learning haskell for only one month.

Sign In or Register to comment.