[Haskell-cafe] Re: Learning about Programming Languages (specifically Haskell)

Samuel Williams space.ship.traveller at gmail.com
Mon May 3 13:15:54 EDT 2010


Dear Kyle,

I've recevied the following program. You did a fantastic job of explaining the other one, but as you said it wasn't a great approach, if you have a moment could you explain this one?

doorOpen :: Int -> Bool
doorOpen door = doh door door

doh :: Int -> Int -> Bool
doh door 0 = True
doh door pass =
	if (door `rem` (pass+1)) == pass
	then not (doh door (pass-1))
	else doh door (pass-1)

doors :: [Bool]
doors = [doorOpen n | n <- [0..]]

printDoor :: (Int,Bool) -> IO ()
printDoor (door,open) =
	putStrLn ("Door #" ++ (show door) ++ " is " ++
		if open then "open." else "closed.")

printUpTo :: Int -> IO ()
printUpTo n =
	mapM_ printDoor (zip [0..(n-1)] doors)

printUpTo 100

Kind regards,
Samuel



More information about the Haskell-Cafe mailing list