fork(1) download
  1. require 'minitest/autorun'
  2.  
  3. #144
  4.  
  5. F=
  6. ->s{a=s.chars.map{|c|[c,c=~/[a-z]/i&&c.upcase.ord-64]}
  7. z=a.size
  8. while i=a.index{|c,s|s}
  9. c,s=a.delete_at i
  10. a.insert (i+s)%z,[c]
  11. end
  12. a.join}
  13.  
  14. describe :MovingLetters do
  15. def test_case_1
  16. assert_equal 'tca', F['cat']
  17. end
  18.  
  19. def test_case_2
  20. assert_equal '.F.NU', F['F.U.N']
  21. end
  22.  
  23. def test_case_3
  24. assert_equal 'goD', F['Dog']
  25. end
  26.  
  27. def test_case_4
  28. assert_equal '*hibey', F['hi*bye']
  29. end
  30. end
  31.  
Success #stdin #stdout 0.09s 10704KB
stdin
Standard input is empty
stdout
Run options: --seed 43274

# Running tests:

....

Finished tests in 0.001174s, 3407.5817 tests/s, 3407.5817 assertions/s.

4 tests, 4 assertions, 0 failures, 0 errors, 0 skips