ptls.dev/online
----------------------------------------------------------
-- Solution to the '100 doors' problem
-- http://rosettacode.org/wiki/100_doors

output =
  range(1, 100)
  |> map(visit(100))
  |> println

----------------------------------------------------------

toggle(state) =
  if state == Closed then Open else Closed

----------------------------------------------------------
-- Door state on iteration i is recursively
-- defined in terms of previous door state

visit(i, index) = cond {
  case (i == 0) Closed
  case (index % i == 0) toggle(lastState)
  else lastState
} where lastState = visit(i - 1, index)