12
1
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
3I didn't count the bigger ones, but doesn't the third one have 11 squares in it? – Value Ink – 2016-05-15T08:37:35.053
@KevinLau-notKenny You're right I made a mistake. – Simon Landry – 2016-05-15T08:39:11.503
I think is too simple, it is counted via a combinatoric form, would you rather prefer to consider the picture format of facebook? – Abr001am – 2016-05-15T08:45:38.090
Is the input always an
nxm
rectangle? (If so, can we just takem
andn
as input, rather than the height + ASCII art?) – Sp3000 – 2016-05-15T08:50:06.437@Agawa001 I'm not sure what you mean by combinatoric, but looking at the 1st test case, there are 16 1x1 squares, 9 2x2 squares, 4 3x3 squares and 1 4x4 square for a total of 30 sub squares. Unless I am completely missing something here, I don't think this is easy to come up with a concise answer. – Simon Landry – 2016-05-15T08:53:57.073
@Sp3000 you can ignore the first line of input in your program if you want, but you cannot change the rest of the input. – Simon Landry – 2016-05-15T08:57:39.140
@Sp3000 Alright learned a new word today, and yes, not saying it is impossible, just not too simple. – Simon Landry – 2016-05-15T09:02:30.223
Actually, I should probably ask to be doubly clear: is the input always an
n
bym
rectangle of unit squares? Because if there can be missing gridlines or other shapes then the problem does get harder. – Sp3000 – 2016-05-15T09:02:53.943@Sp3000 I guess I'll make it so we can be missing gridlines. It seems more interesting of a challenge. I originally intended for it to be a normal rectangle (
n
bym
), but now that you mention it, it shouldn't be too hard to remove some grid lines to make the challenge harder. – Simon Landry – 2016-05-15T09:08:18.4571
For reference, the rectangular case is A271916, which gives
– Sp3000 – 2016-05-15T09:20:23.173m*(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)1@SimonLandry i didnt mean combinatorics in pure sens, i think sp3000 just pointed that out already, the first version of your puzzle (before edit) was open for a simple mathematical breakthrough – Abr001am – 2016-05-15T09:44:32.420
@SimonLandry There are at least three different encodings of box drawing characters. Does it matter which encoding we use for the input? For example, in the list of inputs,
– RootTwo – 2016-05-16T20:31:04.290|
is the keyboard character having code 124. All the others, are the unicode box-drawing-characters starting at code point U+2500.@RootTwo Use whichever encoding you want as input as long as it is visually similar :) – Simon Landry – 2016-05-16T20:35:46.890