Retired

Simple Fun #85: Polygon Perimeter (retired)

70 of 198myjinxin2015

Description:

Task

You have a rectangular white board with some black cells. The black cells create a connected black figure, i.e. it is possible to get from any black cell to any other one through connected adjacent (sharing a common side) black cells.

Find the perimeter of the black figure assuming that a single cell has unit length.

Example

For

matrix = [[false, true,  true ],
          [true,  true,  false],
          [true,  false, false]]```
the output should be `12`.

 ![](https://codefightsuserpics.s3.amazonaws.com/tasks/polygonPerimeter/img/example1.png?_tm=1474901184061)

 For

matrix = [[true, true, true], [true, false, true], [true, true, true]]``` the output should be 16.

Input/Output

  • [input] 2D boolean array matrix

    A matrix of booleans representing the rectangular board where true means a black cell and false means a white one.

    Constraints:

    2 ≤ matrix.length ≤ 10,

    2 ≤ matrix[0].length ≤ 10.

  • [output] an integer

Puzzles

Stats:

CreatedFeb 4, 2017
Warriors Trained400
Total Skips13
Total Code Submissions526
Total Times Completed198
JavaScript Completions70
C# Completions34
Python Completions96
Ruby Completions15
Total Stars8
% of votes with a positive feedback rating95% of 83
Total "Very Satisfied" Votes75
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes0
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • user9644768 Avatar
Ad