Advertisement
gruntfutuk

grid challenge

May 4th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. Adjacent cells challenge
  2.  
  3. Using any programming language, create a program that is capable of identifying all the groups of adjacent cells in a grid.
  4.  
  5. The grid consists of a 2-dimensional array of 0 (zeroes) and 1 (ones). The output of the program should consist of a sequence of multi-dimensional arrays each containing the list of points that make up a group of adjacent cells.
  6.  
  7. Rules:
  8. Cells are considered adjacent if they both contain a 1 (one) and are next to each other horizontally or vertically (not diagonally).
  9. Groups containing a single cell should not be considered
  10. The order of points or groups outputted by the program is not relevant
  11.  
  12. Example
  13. For a grid input of:
  14. [[0,0,0,1,0,0,1,1],
  15. [0,0,1,1,1,0,1,1],
  16. [0,0,0,0,0,0,1,0],
  17. [0,0,0,1,0,0,1,1],
  18. [0,0,0,1,0,0,1,1]]
  19.  
  20. Expected output:
  21. [ [0,3], [1,2], [1,3], [1,4] ]
  22. [ [0,6], [0,7], [1,6], [1,7], [2,6], [3,6], [3,7], [4,6], [4,7] ]
  23. [ [3, 3], [4,3] ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement