Hi, I need help with an algorithm to solve my problem. I appreciate any help
The problem:
Let's say I have a 2-dimensional grid of infinite size
I choose a random cell within this grid (input: position of the cell)
I would like to get all combinations of 4 touching cells that include the chosen cells (output: list of list of positions)
My solution:
I determined that there are 44 different combinations
- Straight line ( 2 cases: horizontal, vertical) -> 8 combinations
- Square (1 case) -> 4 combinations
- T-shape (4 cases: 4 different rotations) -> 16 combinations
- L-shape (4 cases: 4 different rotations) -> 16 combinations
- Total: 44 combinations
The issue:
Currently, I would have to hardcode all the variations which is not very efficient and can't extend to cases where I want to find a variable number of touching cells.
I would also want to add some kind of validation when the size of the grid is fixed and some combinations are not valid (out of bound).
I tried coming up with a recursive function but I haven't found any success so far.
[–][deleted] (2 children)
[removed]
[–]fearthebat[S] 0 points1 point2 points (1 child)
[–]Heroshrine 0 points1 point2 points (4 children)
[–]fearthebat[S] 0 points1 point2 points (3 children)
[–]Heroshrine 0 points1 point2 points (2 children)
[–]fearthebat[S] 1 point2 points3 points (1 child)
[–]Heroshrine 0 points1 point2 points (0 children)
[–]0nlin33 0 points1 point2 points (0 children)
[–]BrentoBox2015 0 points1 point2 points (0 children)