100 doors: Difference between revisions

Content added Content deleted
(→‎{{header|ALGOL 68}}: Use Mediawiki markup for syntax highlighting, bugfix in the optimised version)
Line 984: Line 984:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
'''unoptimized'''
'''unoptimized'''
<syntaxhighlight lang="algol68">
PROC doors = (INT limit)VOID:
(
MODE DOORSTATE = BOOL;
BOOL closed = FALSE;
BOOL open = NOT closed;
MODE DOORLIST = [limit]DOORSTATE;


'''PROC''' doors = ('''INT''' limit)'''VOID''':
DOORLIST the doors;
(
FOR i FROM LWB the doors TO UPB the doors DO the doors[i]:=closed OD;
'''MODE''' '''DOORSTATE''' = '''BOOL''';
'''BOOL''' closed = '''FALSE''';
'''BOOL''' open = '''NOT''' closed;
'''MODE''' '''DOORLIST''' = [limit]'''DOORSTATE''';
'''DOORLIST''' the doors;
'''FOR''' i '''FROM''' '''LWB''' the doors '''TO''' '''UPB''' the doors '''DO''' the doors[i]:=closed '''OD''';
'''FOR''' i '''FROM''' '''LWB''' the doors '''TO''' '''UPB''' the doors '''DO'''
'''FOR''' j '''FROM''' '''LWB''' the doors '''BY''' i '''TO''' '''UPB''' the doors '''DO'''
the doors[j] := '''NOT''' the doors[j]
'''OD'''
'''OD''';
'''FOR''' i '''FROM''' '''LWB''' the doors '''TO''' '''UPB''' the doors '''DO'''
print((whole(i,-12)," is ",(the doors[i]|"opened"|"closed"),newline))
'''OD'''
);
doors(100)


FOR i FROM LWB the doors TO UPB the doors DO
FOR j FROM LWB the doors BY i TO UPB the doors DO
the doors[j] := NOT the doors[j]
OD
OD;
FOR i FROM LWB the doors TO UPB the doors DO
print((whole(i,-12)," is ",(the doors[i]|"opened"|"closed"),newline))
OD
);
doors(100)
</syntaxhighlight>
'''optimized'''
'''optimized'''

<syntaxhighlight lang="algol68">PROC doors optimised = ( INT limit )VOID:
'''PROC''' doors optimised = ( '''INT''' limit )'''VOID''':
FOR i TO limit DO
'''FOR''' i '''TO''' limit '''DO'''
REAL num := sqrt(i);
'''REAL''' num := sqrt(i);
printf(($g" is "gl$,i,(ENTIER num = num |"opened"|"closed") ))
print((whole(i,0)," is ",('''ENTIER''' num = num |"opened"|"closed"),newline))
OD
'''OD'''
;
;
doors optimised(limit)</syntaxhighlight>
doors optimised(100)


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==