Skip to content

Instantly share code, notes, and snippets.

@joom
Created April 27, 2014 19:44
Show Gist options
  • Save joom/11353995 to your computer and use it in GitHub Desktop.
Save joom/11353995 to your computer and use it in GitHub Desktop.
My 100 doors problem solution
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