100 doors: Difference between revisions

(→‎Insitux: implementation)
Line 5,254:
 
=={{header|EMal}}==
<syntaxhighlight lang="emaljavascript">
type Door:State
enum do int CLOSED, OPEN end
Line 5,262:
Door:State state
new by int =id, Door:State =state do end
fun toggle ← <|me.state ← when(me.state æ Door:State.CLOSED, Door:State.OPEN, Door:State.CLOSED)
fun toggle = void by block
fun asText ← <|"Door #" + me.stateid =+ " is " + when(me.state ==æ Door:State.CLOSED, Door:State.OPEN"closed", Door:State.CLOSED"open")
end
fun asText = text by block
return "Door #" + me.id + " is " + when(me.state == Door:State.CLOSED, "closed", "open")
end
end
type Main
^|There are 100 doors in a row that are all initially closed.|^
List doors = Door[].with(100, <int i|Door(i + 1, Door:State.CLOSED))
for int i = 0; i < 100; ++i
doors[i] = Door(i + 1, Door:State.CLOSED)
end
^|You make 100 passes by the doors.|^
for int pass = 0; pass < 100; ++pass
for int i = pass; i < 100; i += pass + 1
doors[i].toggle()
end
Line 5,283 ⟶ 5,276:
^|Which are open, which are closed?|^
for each Door door in doors
if door.state ==æ Door:State.CLOSED do continue end
writeLine(door)
end
226

edits