Haskell I/O Functions - Programmers Heaven

Howdy, Stranger!

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

Categories

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.