fork download
  1. # coding: utf-8
  2. require 'minitest/autorun'
  3.  
  4. F=->s{l=s.split ?\n
  5. b=[]
  6. t={}
  7. [*0...m=l.size].product([*0...n=l[0].size]).map{|y,x|c=l[y][x]
  8. c!=' '&&c>?Z?b<<[c,y,x]:t[c.downcase]=[y,x]}
  9. b.map{|q|c,y,x=q
  10. u,i=t[c]
  11. (m*n).times{|w|e=([u-(y+w)%m,i-(x+w)%n].map &:abs).max
  12. e>c.ord-97||q<<w+e}
  13. q[3]&&[q[3],q[0]]}.compact.sort.map{|a,b|b}}
  14.  
  15.  
  16. describe '#F' do
  17. def test_case_1
  18. assert_equal %w[d a], F[%q{
  19. D
  20. d Aa
  21.  
  22. }]
  23. end
  24.  
  25. def test_case_2
  26. assert_equal %w[w b], F[%q{
  27. W B
  28. A
  29. b
  30.  
  31. a
  32. w
  33. }]
  34. end
  35.  
  36. def test_case_3
  37. assert_equal %w[a], F[%q{
  38.  
  39. A
  40.  
  41.  
  42. a
  43. }]
  44. end
  45.  
  46. def test_case_4
  47. assert_equal %w[i d f], F[%q{
  48.  
  49. i
  50. f d
  51.  
  52.  
  53. DI F }]
  54. end
  55.  
  56. def test_case_5
  57. assert_equal %w[g w j], F[%q{
  58.  
  59.  
  60. g a
  61.  
  62.  
  63. G W
  64.  
  65.  
  66.  
  67.  
  68. j
  69. w
  70.  
  71.  
  72.  
  73. A J
  74.  
  75.  
  76. }]
  77. end
  78. end
  79.  
  80.  
  81.  
Success #stdin #stdout 0.07s 8616KB
stdin
Standard input is empty
stdout
Run options: --seed 28322

# Running tests:

.....

Finished tests in 0.013641s, 366.5393 tests/s, 366.5393 assertions/s.

5 tests, 5 assertions, 0 failures, 0 errors, 0 skips