Number reversal game: Difference between revisions

m (added whitespace to the task's preamble.)
(→‎{{header|XPL0}}: added zkl)
Line 3,232:
Reverse how many digits? 2
5 8 3 1 4 9 7 2 6
</pre>
 
=={{header|zkl}}==
{{trans|AutoHotkey}}
<lang zkl>correctList,scrambledList,N:=[1..9].walk(), correctList.shuffle(),correctList.len();
correctList,scrambledList=correctList.concat(""), scrambledList.concat(""); // list to string
attempts:=0;
while(scrambledList!=correctList){ // Repeat until the sequence is correct
n:=ask(("[%d] %s How many numbers (from the left) should be flipped? ")
.fmt(attempts,scrambledList));
try{ n=n.toInt() }catch{ println("Not a number"); continue; }
if(not (0<=n<N)){ println("Out of range"); continue; }
attempts+=1;
// Reverse the first part of the string and add the second part
scrambledList=scrambledList[0,n].reverse() + scrambledList[n,*];
}
println("You took %d attempts to get the correct sequence.".fmt(attempts));</lang>
{{out}}
<pre>
$ zkl bbb
[0] 145327689 How many numbers (from the left) should be flipped? 7
[1] 672354189 How many numbers (from the left) should be flipped? 2
[2] 762354189 How many numbers (from the left) should be flipped? 7
[3] 145326789 How many numbers (from the left) should be flipped? 3
[4] 541326789 How many numbers (from the left) should be flipped? 5
[5] 231456789 How many numbers (from the left) should be flipped? 2
[6] 321456789 How many numbers (from the left) should be flipped? 3
You took 7 attempts to get the correct sequence.
</pre>
Anonymous user