Question: How to separate and label clusters ( 4 direction connected components) in a list of list number (2-d array) and replace all numbers in a
How to separate and label clusters ( 4 direction connected components) in a list of list number (2-d array) and replace all numbers in a specific cluster to 1 (I need to write this in haskell.) For example, I have a list of string number ( 2d array) like this:
["122221111211", "211121221121", "221211222211", "111212122112", "112121212222", "112222121211", "211211221112"] the cluster will be seperate like this:(the way to label the clusters is like the flood fill, if it connects 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.) And I need to replace all numbers the cluser 21st (which is just number 2) to 1. So the result will be
["122221111211", "211121221121", "221211222211", "111212122112", "112121212222", "112222121211", "111211221112"]
Haskell Code could start like this:
onePlayerOneMove :: [[Char]] -> Int -> [[Char]] onePlayerOneMove game move = game -- "game" will be the list of numbers and "move" will be the specific cluster that needs to be changed the numbers in it
Please help me solve this problem. Many thanks! Haskell code is a must :(
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 2 1,1 2,1, 2,1 2,1 2 2,2,2 1,1, 2,2, 2,2, 2, 1,2 1, 1 ubmingi 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 2 1,1 2,1, 2,1 2,1 2 2,2,2 1,1, 2,2, 2,2, 2, 1,2 1, 1 ubmingi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

(the way to label the clusters is like the flood fill, if it connects 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.) And I need to replace all numbers the cluser 21st (which is just number 2) to 1. So the result will be