Task

Given a jumbled list of the numbers   1   to   9   that are definitely   not   in
ascending order.

Show the list,   and then ask the player how many digits from the
left to reverse.

Reverse those digits,   then ask again,   until all the digits end up in ascending order.



The score is the count of the reversals needed to attain the ascending order.



Note: Assume the player's input does not need extra validation.



Related tasks

   Sorting algorithms/Pancake sort
   Pancake sorting.
   Topswops


Number Reversal Game is a room.
 
The current list is a list of numbers that varies.
 
When play begins:
	now the current list is a shuffled list from 1 to 9;
	now the command prompt is "Current list: [current list in brace notation].[line break]How many items to flip? ".
 
Definition: a list of numbers (called L) is sorted:
	repeat with N running from 1 to the number of entries in L:
		if entry N in L is not N, no;
	yes.
 
To decide which list of numbers is a shuffled list from (min - number) to (max - number):
	let result be a list of numbers;
	repeat with N running from min to max:
		add N to result;
	while true is true:
		sort result in random order;
		if result is not sorted, decide on result.
 
Flipping is an action applying to one number. Understand "[number]" as flipping.
 
Carry out flipping:
	let N be the number understood;
	let L be the current list;
	truncate the current list to the first N entries;
	reverse the current list;
	truncate L to the last (number of entries in L minus N) entries;
	add L to the current list.
 
Report flipping: say "".
 
Every turn:
	if the current list is sorted, end the story saying "You have won".
 
This is the new print final score rule:
	say "It took you [turn count] flip[s] to sort the list."
 
The new print final score rule is listed instead of the print final score rule in the for printing the player's obituary rules.