fork download
  1. require 'minitest/autorun'
  2.  
  3. F=->d,l{
  4. i=0
  5. t=d.map{|x|[x,d.size-(i+=1)]}
  6. r=[]
  7. d.cycle.map{|n|
  8. t==[]&&break
  9. (c=t.find{|x,_|x==n})&&(s=n
  10. w=c[1]
  11. o=p
  12. (a=(t-[c]).map{|_,p|p%l}
  13. s-=1;w+=1
  14. a&[w%l]==[]?(o=p;c[1]=w):o||s-=o=1)while s>0
  15. c[1]>=n*l&&(t.delete c;r<<n))}
  16. r}
  17.  
  18. describe '#F' do
  19. # break
  20. def test_case_1
  21. assert_equal [3], F[[3], 2]
  22. end
  23.  
  24. def test_case_2
  25. assert_equal [9, 5], F[[9, 5], 3]
  26. end
  27.  
  28. def test_case_3
  29. assert_equal [2, 9, 5], F[[5, 9, 2], 6]
  30. end
  31.  
  32. def test_case_4
  33. assert_equal [5, 9, 2], F[[5, 9, 2], 10]
  34. end
  35.  
  36. def test_case_5
  37. assert_equal [1, 5, 7, 8, 2], F[[5, 7, 8, 1, 2], 10 ]
  38. end
  39.  
  40. def test_case_6
  41. assert_equal [1, 6, 8, 2, 3, 5], F[[5, 1, 6, 8, 3, 2], 17 ]
  42. end
  43.  
  44. def test_case_7
  45. assert_equal [1, 7, 8, 9, 2, 3], F[[1, 2, 3, 7, 8, 9], 15 ]
  46. end
  47.  
  48. def test_case_8
  49. assert_equal [8, 7, 9, 1, 2, 3], F[[9, 8, 7, 3, 2, 1], 15 ]
  50. end
  51.  
  52. def test_case_9
  53. assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9], F[[1, 2, 3, 4, 5, 6, 7, 8, 9], 20 ]
  54. end
  55.  
  56. def test_case_10
  57. assert_equal [8, 7, 5, 9, 6, 1, 2, 4, 3], F[[9, 8, 7, 6, 5, 4, 3, 2, 1], 20 ]
  58. end
  59. end
Success #stdin #stdout 0.14s 8624KB
stdin
Standard input is empty
stdout
Run options: --seed 39178

# Running tests:

..........

Finished tests in 0.097661s, 102.3953 tests/s, 102.3953 assertions/s.

10 tests, 10 assertions, 0 failures, 0 errors, 0 skips