Flipping bits game: Difference between revisions
Content added Content deleted
(shorter example!) |
m (→{{header|REXX}}: changed some comments.) |
||
Line 1,724: | Line 1,724: | ||
This REXX version allows the specification (on the invocation line) for: |
This REXX version allows the specification (on the invocation line) for: |
||
:::* the size of the array (grid) [default is 3] |
:::* the size of the array (grid) [default is 3] |
||
:::* the number of bits (for the target) to be set [default is |
:::* the number of bits (for the target) to be set [default is size of the grid] |
||
:::* the characters which are used for the '''on''' and '''off''' [defaults are '''1''' and '''0'''] |
:::* the characters which are used for the '''on''' and '''off''' [defaults are '''1''' and '''0'''] |
||
<lang rexx>/*REXX program presents a "flipping bit" puzzle, user can solve via C.L.*/ |
<lang rexx>/*REXX program presents a "flipping bit" puzzle, user can solve via C.L.*/ |
||
parse arg N u on off . |
parse arg N u on off . /*get optional arguments. */ |
||
if N=='' | N==',' then N=3 /*Size given? Then use default.*/ |
if N=='' | N==',' then N=3 /*Size given? Then use default.*/ |
||
if u=='' | u==',' then u=N /*number of bits initialized ON.*/ |
if u=='' | u==',' then u=N /*number of bits initialized ON.*/ |
||
Line 1,735: | Line 1,735: | ||
col@='a b c d e f g h i j k l m n o p' /*letters to be used for col id. */ |
col@='a b c d e f g h i j k l m n o p' /*letters to be used for col id. */ |
||
@.=off; !.=off /*set both arrays to "off" chars.*/ |
@.=off; !.=off /*set both arrays to "off" chars.*/ |
||
tries=0 /*# of player's attempts used. */ |
|||
do while show(0)<u /* [↓] turn "on" U bits.*/ |
|||
r=random(1,N); c=random(1,N) /*get a random row and column.*/ |
|||
@.r.c=on ; !.r.c=on /*set (both) row & column to ON*/ |
|||
end /*while*/ /* [↑] keep going 'til U bits set*/ |
|||
oz=z /*keep the original array string.*/ |
oz=z /*keep the original array string.*/ |
||
call show 1, ' ◄───target' /*show target for user to attain.*/ |
call show 1, ' ◄───target' /*show target for user to attain.*/ |
||
Line 1,810: | Line 1,811: | ||
<br>Note that the user's input is also shown. |
<br>Note that the user's input is also shown. |
||
<br>Also note that the 2<sup>nd</sup> answer was a blank (or nothing), which caused the program to re-show the target array. |
<br>Also note that the 2<sup>nd</sup> answer was a blank (or nothing), which caused the program to re-show the target array. |
||
<pre style="height:75ex"> |
|||
<pre> |
|||
a b c column letter |
a b c column letter |
||
row ╔═══════ |
row ╔═══════ |