Skip to content

Instantly share code, notes, and snippets.

@thistleknot
Created November 25, 2023 20:40
Show Gist options
  • Save thistleknot/87983a911e7a58fef3e810869b5922e8 to your computer and use it in GitHub Desktop.
Save thistleknot/87983a911e7a58fef3e810869b5922e8 to your computer and use it in GitHub Desktop.
turing prompt
Problem: 2, 3, 1, 5
EXECUTION
Prep
Length of the list: 4
Number of consecutive pairs: 3
a=[2 3 1 5]
set n_swaps=0
EndPrep
Iteration:
set swap_flag=false. The state is:
State: a=[2 3 1 5], n_swaps=0, swap_flag=false EndState
Pair a[1,2] = [2 3] Check if 2<3. Is it true? Yes.
Because of that, we leave state as is
State: a=[2 3 1 5], n_swaps=0, swap_flag=false
Pair a[2,3]= [3 1] Check if 3<1. Is it true? No.
Thus, we swap_flag=true, increase n_swaps by one,
and in the latest a=[2 3 1 5] swap 3 and 1 to get into state:
State: a=[2 1 3 5], n_swaps=1, swap_flag=true EndState
Pair a[3,4]= [3 5] Check if 3<5. Is it true? Yes.
Because of that, we leave state as is
State: a=[2 1 3 5], n_swaps=1, swap_flag=true EndState
swap_flag is true, so do another iteration
Iteration:
set swap_flag=false. The state is:
State: a=[2 1 3 5], n_swaps=1, swap_flag=false EndState
Pair a[1,2] = [2 1] Check if 2<1. Is it true? No.
Thus, we set swap_flag=true, increase n_swaps by one,
and in the latest a=[2, 1, 3, 5] swap 2 and 1 to get into state:
State: a=[1 2 3 5], n_swaps=2, swap_flag=true EndState
Pair a[2,3] = [2 3] Check if 2<3. Is it true? Yes.
Because of that, we leave state as is
State: a=[1 2 3 5], n_swaps=2, swap_flag=true EndState
Pair a[3,4] = [3 5] Check if 3<5. Is it true? Yes.
Because of that, we leave state as is
State: a=[1 2 3 5], n_swaps=2, swap_flag=true EndState
swap_flag is true, so do another iteration
Iteration:
set swap_flag=false. The state is:
State: a=[1 2 3 5], n_swaps=2, swap_flag=false EndState
Pair a[1,2] = [1 2] Check if 1<2. Is it true? Yes.
Because of that, we leave state as is
State: a=[1 2 3 5], n_swaps=2, swap_flag=false EndState
Pair a[2,3] = [2 3] Check if 2<3. Is it true? Yes.
Because of that, we leave state as is
State: a=[1 2 3 5], n_swaps=2, swap_flag=false EndState
Pair a[3,4] = [3 5] Check if 3<5. Is it true? Yes.
Because of that, we leave state as is
State: a=[1 2 3 5], n_swaps=2, swap_flag=false EndState
swap_flag is false, so stop the iteration
Final List: 1, 2, 3, 5
Number of swaps: 2
END OF EXECUTION
Problem: 0, 3, 8, 5, 6
EXECUTION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment