The Number of Islands

This problem is from Number of Islands (YouTube). It is an interesting problem. Click HERE for more information.

Introduction

Given a m x n 2D grid which represents a map of '1's (land) and '0's (water).

An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are surrounded by water.

The code in the video is JavaScript. Re-code/re-structure it in Python.

Project #1

Given a m x n 2D grid, display the grid and the number of islands.

Grids from the videos:

grid1 = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ]

grid2 = [ ["1","1","0","0","0"], ["1","1","0","0","0"], ["0","0","1","0","0"], ["0","0","0","1","1"] ]

Note: Create several more grids for testing.

Project #2

Read grids from files. (CSV? JSON? ...? One grid per file? Multiple grids per file?)

Project #3

Same as Project #1 and Project #2 but display:

Project #4

Modify the code so that diagonal '1's (land) are also part of an island.

Project #5

Generate random grids. (write to a file?)

Use random island sizes and orientations within the grid.