Question: (Haskell Language). How to separate and label clusters ( 4 direction connected components) in a 2D array? ( Haskell code will be a must :(
(Haskell Language). How to separate and label clusters ( 4 direction connected components) in a 2D array? ( Haskell code will be a must :(
For example, I have a list of list number in haskell like this:
["122221111211", "211121221121", "221211222211", "111212122112", "112121212222", "112222121211", "211211221112"]
And I want to label the connected components (4 directions)to be like this:
"1 2 2 2 2 3 3 3 3 4 5 5" "6 7 7 7 2 3 8 8 3 3 9 5" "6 6 7 10 3 3 8 8 8 8 5 5" "7 7 7 10 3 11 12 8 8 5 5 8" "7 7 13 14 13 15 16 17 8 8 8 8" "7 7 13 13 13 13 18 19 20 8 20 20" "21 7 7 13 22 22 19 19 20 20 20 23"
the color version:

the way to label the clusters is like the flood fill, if it connects (same number) to their neighbor by up-down-left-right direction, they will be grouping in the same cluster. we go from top left to bottom right. Please help me solve this problem. Thanks!!! (I have to write this by Haskell)
c 15 15 21 121 221 1 12 11 1221 1 12 1211 3.8.2 Input File 21,20, 18, 16, 12,6 1 1.1., 1,2, 1 2 2,1 1 2,1 2,2, 1,2, 1 1, 2,2,2,2, 1, 1 1,1 2, 1, 2, 1.2 1,1 1,1 2 2,1 1 2 2 2 2 1,1, 2, 2, 2,2, 1.2 1,2, 1,1 3.8.3 Submission output 1 122221 111211 2 211121221 121
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
