fork(2) download
  1.  
  2. DRUNKEN_BISHOP=
  3. ->k{w=17
  4. r=[z=?++?-*w+?+]
  5. (0...w*9).each_slice(w).map{|o|r<<?|+o.map{|x|c=76
  6. q=0
  7. k.split(?:).flat_map{|b|(0..7).map{|i|b.to_i(16)[i]}}.each_slice(2){|h,v|v<1?(c>w&&c-=w):c<w*8&&c+=w
  8. c+=h<1?c%w>0?-1:0:c%w<16?1:0
  9. c==x&&q+=1}
  10. x==76??S:c==x ??E:' .o+=*BOX@%&#/^'[q]}.join+?|}
  11. (r+[z]).join'
  12. '}
  13.  
  14.  
  15. require 'minitest/autorun'
  16.  
  17. describe DRUNKEN_BISHOP do
  18. def test_case_1
  19. assert_equal <<-EOS.chomp, DRUNKEN_BISHOP['37:e4:6a:2d:48:38:1a:0a:f3:72:6d:d9:17:6b:bd:5e']
  20. +-----------------+
  21. | |
  22. | |
  23. | . |
  24. | . o |
  25. |o . o . S + |
  26. |.+ + = . B . |
  27. |o + + o B o E |
  28. | o . + . o |
  29. | .o |
  30. +-----------------+
  31. EOS
  32. end
  33.  
  34. def test_case_2
  35. assert_equal <<-EOS.chomp, DRUNKEN_BISHOP['16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48']
  36. +-----------------+
  37. | . |
  38. | + . |
  39. | . B . |
  40. | o * + |
  41. | X * S |
  42. | + O o . . |
  43. | . E . o |
  44. | . . o |
  45. | . . |
  46. +-----------------+
  47. EOS
  48. end
  49.  
  50. def test_case_3
  51. assert_equal <<-EOS.chomp, DRUNKEN_BISHOP['b6:dd:b7:1f:bc:25:31:d3:12:f4:92:1c:0b:93:5f:4b']
  52. +-----------------+
  53. | o.o |
  54. | .= E.|
  55. | .B.o|
  56. | .= |
  57. | S = .|
  58. | . o . .= |
  59. | . . . oo.|
  60. | . o+|
  61. | .o.|
  62. +-----------------+
  63. EOS
  64. end
  65.  
  66. def test_case_4
  67. assert_equal <<-EOS.chomp, DRUNKEN_BISHOP['05:1e:1e:c1:ac:b9:d1:1c:6a:60:ce:0f:77:6c:78:47']
  68. +-----------------+
  69. | o=. |
  70. | o o++E |
  71. | + . Ooo. |
  72. | + O B.. |
  73. | = *S. |
  74. | o |
  75. | |
  76. | |
  77. | |
  78. +-----------------+
  79. EOS
  80. end
  81. end
  82.  
  83.  
  84.  
  85.  
  86.  
Success #stdin #stdout 0.19s 10752KB
stdin
Standard input is empty
stdout
Run options: --seed 34182

# Running tests:

....

Finished tests in 0.097862s, 40.8740 tests/s, 40.8740 assertions/s.

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