I need help grouping elements in a NxM matrix
Imagine a scenario where we have an NxM matrix representing a container, with indices indicating possible locations for stacking marbles. The goal is to group marbles based on their color and ensure they re in neighboring indices. It s important to note that the groups can have different numbers of marbles (i.e. 6 red marbles, 3 blue marbles, 9 gold).
To achieve this, I attempted to write Python code that accomplishes the following tasks:
- Takes input from the user to create an NxM matrix.
- Tries to divide the matrix into submatrices based on the number of groups and number of marbles in each group.
- However, I encountered difficulties in allocating square submatrices of varying sizes within the matrix, and my code doesn t function properly.
I m currently struggling to find the most suitable approach. It d even be acceptable if the "submatrices" are treated as clusters rather than square matrices.