fork download
  1. pathCount :: [[Bool]] -> Int
  2. pathCount matrix = count (0,0)
  3. where
  4. n = length matrix - 1
  5. count (i,j) = if i == n && j == n then 1 else a + b
  6. where
  7. a = if j == n || ((matrix !! i) !! (j+1)) then 0 else count (i, j + 1)
  8. b = if i == n || ((matrix !! (i+1)) !! j) then 0 else count (i + 1, j)
  9.  
  10. testMatrix1 :: [[Bool]]
  11. -- ...
  12. -- .#.
  13. -- ...
  14. testMatrix1 = [[ False, False, False ],[ False, True, False ],[ False, False, False ]]
  15. testMatrix2 = map (map (== '#')) [
  16. ".#..",
  17. "...#",
  18. ".#..",
  19. "...."
  20. ]
  21. testMatrix3 = map (map (== '#')) [
  22. "..#.",
  23. "..#.",
  24. "....",
  25. ".##."
  26. ]
  27.  
  28. main = do
  29. print (pathCount testMatrix1) -- 2
  30. print (pathCount testMatrix2) -- 3
  31. print (pathCount testMatrix3) -- 3
  32.  
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
2
3
3