RB
rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def shuffle(arr, mv)
arr[mv-1], arr[-mv]= arr[-mv], arr[mv-1]
return arr
end
def game(cups, trgt, swaps)
swap = 1
while (swaps.length >= swap)
cups = shuffle(cups, swaps[swap-1])
swap+=1
end
puts "Cup No. #{trgt} is at position #{cups.find_index(trgt)+1}"
end
puts "----------------"
game([ 1, 2 ] , 1 , [ 1, 2, 2, 2, 1 ])
#"Cup no. 1 at position 2."
puts "----------------"
game([ 1, 2, 3 ] , 2 , [ 1, 3 ])
#"Cup no. 2 at position 2."
puts "----------------"
game([ 1, 2, 3, 4, 5 ] , 4 , [ 3, 1, 4, 5, 2 ])
#"Cup no. 4 at position 4."
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run