fork download
  1. f=->s{
  2. r=s.dup
  3. l=s.index(?\n)+1
  4. (0...s.size).map{|i|
  5. s[i]<?0||r[i]=r[i]<?1??.:[i-1,i+1,i-l,i+l].map{|n|n<0??0:s[n]||?0}.max>r[i]??-:s[i]}
  6. r}
  7.  
  8.  
  9. require 'minitest/autorun'
  10.  
  11. describe '#f' do
  12. it 'passes test case #1' do
  13. f[
  14. '898778765432100
  15. 787667654321100
  16. 677656543211210
  17. 678765432112321
  18. 567654321123210']
  19. .must_equal \
  20. '-9---8-------..
  21. -------------..
  22. --------------.
  23. --8---------3--
  24. -----------3--.'
  25. end
  26.  
  27. it 'passes test case #2' do
  28. f[
  29. '7898
  30. 8787
  31. 7676
  32. 6565']
  33. .must_equal \
  34. '--9-
  35. 8---
  36. ----
  37. ----'
  38. end
  39.  
  40. it 'passes test case #3' do
  41. f[
  42. '00001
  43. 00000
  44. 00000
  45. 10000']
  46. .must_equal \
  47. '....1
  48. .....
  49. .....
  50. 1....'
  51. end
  52.  
  53. it 'passes test case #4' do
  54. f[
  55. '34565432100100000000
  56. 45676543210000000000
  57. 56787654321000000110
  58. 45676543210000001221
  59. 34565432100000012321
  60. 23454321000000123432
  61. 12343210000001234543
  62. 01232100000012345654
  63. 00121000000011234543
  64. 00010000000121123432']
  65. .must_equal \
  66. '---------..1........
  67. ----------..........
  68. ---8-------......--.
  69. ----------......--2-
  70. ---------......-----
  71. --------......------
  72. -------......-------
  73. .-----......-----6--
  74. ..---.......--------
  75. ...-.......-2-------'
  76. end
  77. end
Success #stdin #stdout 0.06s 8536KB
stdin
Standard input is empty
stdout
Run options: --seed 30964

# Running tests:

....

Finished tests in 0.002308s, 1732.7839 tests/s, 1732.7839 assertions/s.

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