fork download
  1. def f(aa, a, b)
  2. i = aa.index(a)
  3. sa = aa[i..-1] + aa[0, i]
  4. sa -= (sa - b)
  5. i = b.index(sa[0])
  6. b[i..-1] + b[0,i]
  7. end
  8.  
  9. p f([2,3,5,7,9], 2, [9,2,5])
  10. p f([2,3,5,7,9], 9, [9,2,5])
  11. p f([2,3,5,7,9], 5, [9,2,5])
  12. p f([2,3,5,7,9], 3, [9,2,5,5,2])
  13.  
Success #stdin #stdout 0.01s 7412KB
stdin
Standard input is empty
stdout
[2, 5, 9]
[9, 2, 5]
[5, 9, 2]
[5, 5, 2, 9, 2]