File size: 663 Bytes
497f2f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\ Array of doors; init to empty; accessing a non-extant member will return
\ 'null', which is treated as 'false', so we don't need to initialize it:
[] var, doors    

\ given a door number, get the value and toggle it:
: toggle-door \ n --
	doors @ over a:@
	not rot swap a:! drop ;

\ print which doors are open:
: .doors
	( 
		doors @ over a:@ nip
		if . space else drop then
	) 1 100 loop ;

\ iterate over the doors, skipping 'n':
: main-pass \ n --
	0
	true
	repeat
		drop
		dup toggle-door
		over n:+
		dup 101 <
	while 2drop drop ;

\ calculate the first 100 doors:
' main-pass 1 100 loop
\ print the results:
.doors cr bye