fork download
  1. res=
  2. ->d{c=->d,f,v,u{i=0
  3. r=[]
  4. d.map{|y|j=0
  5. e=[]
  6. y.map{|x|f[j]||=[]
  7. f[j][i]=x
  8. x==v ?e[1]?r<<e+[x]&&e=[x]:e[0]?e=[x]:e<<x :x==u&&e[0]?e<<x :e=[]
  9. j+=1}
  10. i+=1}
  11. r}
  12. y=c[d.split.map(&:chars),f=[],?|,?-]+c[f,[],?-,?|]
  13. y.count{|x|y.all?{|q|x.equal?(q)||!(q+x).uniq!(&:object_id)}}}
  14.  
  15. tests=[
  16. "
  17. |#|-|#|##
  18. #||--|||#
  19. ###|#|--#
  20. ###-||--|
  21. -#-|#-|#-
  22. #---#-#-|
  23. #-#-|#--|
  24. ",
  25. "
  26. ##--
  27. ||##
  28. -#|-
  29. |#|#
  30. ",
  31. "
  32. -##|-##--
  33. #|#-|#||-
  34. --|-#|#||
  35. ##||||-##
  36. ||#|--|-|
  37. -#|-#--|#
  38. |####|#-#
  39. ",
  40. "
  41. #|--|---|-|#
  42. ####|##--||-
  43. -|-##||#|---
  44. -#|#-|-#-|||
  45. #|-##--###|-
  46. ---#-||-#-##
  47. #|---|###|-#
  48. -|---#-#|#|#
  49. |#--|####-|-
  50. ",
  51. "
  52. -|-||---##|#
  53. ---|######-#
  54. ####-##|#--|
  55. |||##|#-||||
  56. ####-#-||-#|
  57. ---#--|#-#--
  58. -|#-####-##-
  59. #||-|-|-###|
  60. |-##||-||-#-
  61. ",
  62. "
  63. |#-|#|#-###|#-#
  64. ----#####|#----
  65. |#--#-##-#|##-|
  66. |#-|#-|--##||--
  67. ||#-#---##|||##
  68. #|#-|||-#-#--||
  69. --#|-||#|--|#|#
  70. -#-|###||-#--#|
  71. -#||-|#-##||##|
  72. |--|-|||-##|-#|
  73. ",
  74. "
  75. ||-|-|-##-#-#-|#--#-
  76. -##|-#|-#-##-|#|--|-
  77. ||#---###||-|#|##|-#
  78. #||-#-#-|---|#||#|##
  79. -#-###-##-|-#-|-#||#
  80. ##-#--#||-----||-|##
  81. -|--#-#-#|---#-#|#-#
  82. ###|-|#-#|-|###|#-|#
  83. #||#-#|--|-||#------
  84. ||##|-||#-|--#|#-#-#
  85. |#-|-#-|-|--##-#|||#
  86. -|#--#||##---##|-##-
  87. #|-|-|-||-||#-#-|##-
  88. |-#|##|-|#|#|--||#--
  89. ",
  90. ]
  91.  
  92. puts "expected: 2004549"
  93. print "result: "
  94. tests.each{|x|print res[x]}
Success #stdin #stdout 0.02s 7532KB
stdin
Standard input is empty
stdout
expected: 2004549
result:   2004549