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 game(cups, trgt, swaps)
origin_place = cups.index(trgt)+1
opposite_place = cups.length-cups.index(trgt)
# if there is an even amount of out and back to place it should be in starting pos
if ((swaps.count(origin_place) + swaps.count(opposite_place)) % 2 == 0)
puts "Cup No. #{trgt} is at position #{origin_place}."
# else it must be in the opposite place
else
puts "Cup No. #{trgt} is at position #{opposite_place}."
end
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."
puts "----------------"
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run