Finding Squares in Matrices
I don't usually take part in the Perl Weekly Challenge but one of this week's challenges caught my eye. I thought it could be a fun thing to attempt and decided to use Zydeco to help solve it.
The problem is that you're given a matrix of 0s and 1s:
You need to find any squares (equal length sides) where all four corners are 1s:
Arguably it's not a task best suited for object-oriented programming; a more functional style might suit the problem better, but this is how I did it.
Sample output:
Found size 2 square at 1, 2. Found size 3 square at 1, 6. Found size 2 square at 2, 1. Found size 1 square at 3, 1. Found 4 squares.
Leave a comment