fork download
  1. F=
  2. ->b{s=->l,w=p{c,*x=l.map &:dup
  3. v=[1,3,3,5,9,0]['PBNRQ'.index(c[y=w||c.index(?L)])||5]
  4. w&&c[y]=?X
  5. (n=x[0])?(m=[]
  6. [y-1,y,y+1].map{|z|(z==y)^(n[z]>?.)&&m<<s[x,z]}
  7. q,r=m.max_by{|m|m ?m[0]:0}
  8. q&&[q+v,c+r]):[v,c]}
  9. s[b.lines][1]}
  10.  
  11. require 'minitest/autorun'
  12.  
  13. describe F do
  14. def test_case_1
  15. input = <<-EOS
  16. ----L---
  17. -----P--
  18. ------P-
  19. --R--P-Q
  20. ----P-P-
  21. ---P-P-P
  22. --P-N---
  23. -P------
  24. EOS
  25.  
  26. F[input].must_equal <<-EOS
  27. ----L---
  28. -----X--
  29. ------X-
  30. --R--P-X
  31. ----P-X-
  32. ---P-X-P
  33. --P-X---
  34. -P--X---
  35. EOS
  36. end
  37.  
  38. def test_case_2
  39. input = <<-EOS
  40. --L-----
  41. -P------
  42. P-------
  43. -P------
  44. P--Q----
  45. -P------
  46. P-------
  47. -P------
  48. EOS
  49.  
  50. F[input].must_equal <<-EOS
  51. --L-----
  52. -PX-----
  53. P-X-----
  54. -PX-----
  55. P--X----
  56. -P-X----
  57. P--X----
  58. -P-X----
  59. EOS
  60. end
  61.  
  62. end
  63.  
Success #stdin #stdout 0.09s 10736KB
stdin
Standard input is empty
stdout
Run options: --seed 63171

# Running tests:

..

Finished tests in 0.002346s, 852.4125 tests/s, 852.4125 assertions/s.

2 tests, 2 assertions, 0 failures, 0 errors, 0 skips