Anonymous user
100 doors: Difference between revisions
→{{header|8086 Assembly}}
(→Unoptimized with Modulus % Operator: Removing unnecessary brackets.) |
|||
Line 228:
=={{header|8086 Assembly}}==
See [[100 doors/8086 Assembly]]
=={{header|8th}}==
<lang forth>
\ 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
</lang>
{{out}}
1 4 9 16 25 36 49 64 81 100
=={{header|ABAP}}==
|