This challenge is inspired by a picture that often roams on Facebook that looks like this. Except our base square will look more like this:
┌─┬───┬─┐
├─┼─┬─┼─┤
├─┼─┴─┼─┤
├─┼─┬─┼─┤
└─┴─┴─┴─┘
The square is made out of n x m
1x1 square, you have to count how many sub-squares (1x1, 2x2, 3x3, 4x4, 5x5, etc.) can fit within that square. Squares can be missing some grid lines (like in the example above) or be complete like in the example bellow. Which means a mathematical breakdown is not possible (as far as I know).
Inputs:
- The amount of lines (
n
) of input to build the square; - A square made from the following characters:
─
┐
┌
└
┴
┘
┬
├
┤
┼
|
acrossn
lines of input.
Output:
- The amount of squares of any size that can fit within the input square (we only want a single number here, not a number for each size).
Winning criterion:
The smallest answer (number of bytes) wins.
Test Cases:
In:
5
┌─┬─┬─┬─┐
├─┼─┼─┼─┤
├─┼─┼─┼─┤
├─┼─┼─┼─┤
└─┴─┴─┴─┘
Out: 30
In:
3
┌─┬─┐
├─┼─┤
└─┴─┘
Out: 5
In:
5
┌─┬─┐
├─┴─┤
├───┤
├─┬─┤
└─┴─┘
Out: 7
In:
4
┌─┬─┬─┬─┬─┬─┐
├─┼─┼─┼─┼─┼─┤
├─┼─┼─┼─┼─┼─┤
└─┴─┴─┴─┴─┴─┘
Out: 32
In:
2
┌─┐
└─┘
Out: 1
In:
4
┌─┬─┬─┬─┬─┬─┐
├─┴─┼─┼─┼─┴─┤
├─┬─┼─┼─┼─┬─┤
└─┴─┴─┴─┴─┴─┘
Out: 22
m*(m+1)*(3*n-m+1)/6
for anm
byn
rectangle withn >= m
(dimensions offset by one since the entry speaks of points rather than the squares themselves) \$\endgroup\$ – Sp3000 May 15 '16 at 9:20