Draft

Non-recursive Island Count

Description:

Given a string representation of a 2d map, return the number of islands in the map.

  • Land spaces are denoted by a zero.
  • Water is denoted by a dot.
  • Rows are denoted by newlines ('\n').
  • Two land spaces are considered connected if they are adjacent (horizontal or vertical, but not diagonal).

Too hard? Try solving it with recursion.

Example:

You may be given the string ".0...\n.00..\n....0" as input.

This correlates to a grid, like this:

.0...
.00..
....0

This would be an example of a map that contains two islands; one with 3 pieces of land, one with 1 piece of land.

More example:

This is 5 islands:

0...0
..0..
0...0

This is 3 islands:

..000.
..000.
..000.
.0....
..000.

Puzzles

More By Author:

Check out these other kata created by finetype

Stats:

CreatedOct 5, 2015
Warriors Trained149
Total Skips14
Total Code Submissions121
Total Times Completed35
JavaScript Completions35
Total Stars4
% of votes with a positive feedback rating71% of 17
Total "Very Satisfied" Votes10
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes3
Total Rank Assessments19
Average Assessed Rank
5 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • finetype Avatar
  • asmgf Avatar
Ad