fork download
  1. from itertools import*
  2. def f(b):
  3. C=count();v=[*zip(*[[k for _,b in groupby(j)for k in[next(C)]*len([*b])]for j in zip(*b)])];q,S=[(0,0,[v[0][0]])]*('#'!=b[0][0]),[];J=len(b);K=len(b[0])
  4. for x,y,p in q:
  5. if J-x==1==K-y:S+=p,;continue
  6. for n,m in[(x+1,y),(x,y+1)]:
  7. if n<J and m<K and'.'==b[n][m]:q+=(n,m,p+[v[n][m]]),
  8. return len({tuple({*i})for i in S})
  9.  
  10. s1 = """
  11. ....
  12. ....
  13. ....
  14. """
  15. s2 = """
  16. ...#
  17. ....
  18. ...#
  19. """
  20. s3 = """
  21. #..#
  22. ..#.
  23. ....
  24. """
  25. s4 = """
  26. ......
  27. ......
  28. ..##..
  29. ......
  30. ......
  31. """
  32. s5 = """
  33. ......
  34. ...#..
  35. ......
  36. ..#...
  37. #.....
  38. """
  39. s6 = """
  40. ......
  41. ..#...
  42. ......
  43. ....#.
  44. #.....
  45. """
  46. s7 = """
  47. .......
  48. ##.....
  49. ....###
  50. ...#...
  51. ..##.#.
  52. #....#.
  53. ..#....
  54. """
  55. s8 = """
  56. ......#.
  57. ..##....
  58. ...#....
  59. .......#
  60. ....#...
  61. .##...#.
  62. ....#...
  63. ##......
  64. """
  65. s9 = """
  66. .........
  67. .#.#.#.#.
  68. .........
  69. #.#...#.#
  70. .........
  71. .#.#.#.#.
  72. .........
  73. """
  74. s10 = """
  75. ..........
  76. .#........
  77. ..........
  78. .....#....
  79. #.........
  80. ........#.
  81. ......#...
  82. ..........
  83. """
  84. s11 = """
  85. .........
  86. .#.......
  87. .........
  88. ...#.....
  89. .........
  90. .....#...
  91. .........
  92. .......#.
  93. .........
  94. """
  95. def to_board(s):
  96. return [[*i]for i in filter(None, s.split('\n'))]
  97.  
  98. print(f(to_board(s1)))
  99. print(f(to_board(s2)))
  100. print(f(to_board(s3)))
  101. print(f(to_board(s4)))
  102. print(f(to_board(s5)))
  103. print(f(to_board(s6)))
  104. print(f(to_board(s7)))
  105. print(f(to_board(s8)))
  106. print(f(to_board(s9)))
  107. print(f(to_board(s10)))
  108. print(f(to_board(s11)))
Success #stdin #stdout 0.08s 15192KB
stdin
Standard input is empty
stdout
1
0
0
2
3
4
0
7
17
10
16