Created
April 27, 2014 19:44
-
-
Save joom/11353995 to your computer and use it in GitHub Desktop.
My 100 doors problem solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data DoorState = Open | Closed deriving (Show, Eq) | |
switch Open = Closed | |
switch Closed = Open | |
initial = map (\n -> (n, Closed)) [1..100] | |
visitMult xs n = map change xs | |
where mult x y = x `mod` y == 0 | |
change (x, st) = (x, if x `mult` n then switch st else st) | |
visitUpTo xs n = if n > 0 then (xs `visitMult` n) `visitMult` (n-1) else xs | |
main = do | |
print $ initial `visitUpTo` 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment