Beta

Count unique shapes

Description:

You played Tetris, didn't you?

Synopsis

You are given a 2d area which looks like this:

To solve the Kata you need to calculate 2 numbers:

  1. number of pieces on the area
  2. number of unique shapes on the area

Rules

  • 2 shaped pieces that touch each other horizontally or vertically are considered a single piece. For instance:

  • 2 shaped pieces that touch each other diagonally are considered 2 distinct pieces. For instance:

  • 2 pieces are considered to be of the same shape if one piece can be derived from the other by applying rotation, horizontal flipping or linear scaling

Example

Let's calculate pieces and shapes on the example area above: There are exactly 11 shaped pieces but only 5 unique shapes:

Note that 2 following pieces have the same shape but different scale.

And the following pieces also have the same shape but differently rotated / flipped.

I/O

Input - 2d array with 1s and 0s (ie binary). 1 is a part of a piece, 0 is an empty space.

Output - Tuple (Count_of_pieces, Count_of_unique_shapes).

see test examples for more details

Geometry
Arrays
Algorithms

Stats:

CreatedFeb 5, 2023
PublishedFeb 5, 2023
Warriors Trained66
Total Skips22
Total Code Submissions107
Total Times Completed5
C# Completions5
Total Stars4
% of votes with a positive feedback rating83% of 3
Total "Very Satisfied" Votes2
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments2
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • oleggozhyi Avatar
  • trashy_incel Avatar
Ad