suppose I have a list of list xs. Each element in xs has the same length (e.g. xs is not like [[1,2],[1],[1,2,3]]). And I have a function f, which return a Bool. I want to apply f to each of the 2x2 grid in xs and get the AND result of the applications.
For example,
xs = [[1,2,3],[4,5,6],[7,8,9]]
f :: [[Int]] -> Bool
f [[1,_][_,_]] = False
f _ = True
In this case, I want to
- apply
fto[[1,2],[4,5]]and returnFalse - apply
fto[[2,3],[5,6]]and returnTrue - apply
fto[[4,5],[7,8]]and returnTrue - apply
fto[[5,6],[8,9]]and returnTrue
Then the final result should be False as 3 Trues and 1 False result in False.
Currently I write a function that help me to extract a 2x2 grid from the list
get_grid :: [[Int]] -> [[Int]]
get_grid xs = map (take 2) (take 2 xs)
Is there any way to iterate over xs by get_grid and apply f in each iteration and AND the result?
Thanks for any help.