Given a non-empty array of positive integers, determine if it is possible to take squares with side lengths specified by each integer, and arrange them in space such that they form a square.
The output can have anything as truthy / falsey values, and the input array may contain duplicates.
For the truthy testcase [3,2,2,2,1,1,1,1]
, a possible way to arrange the square is:
aaabb
aaabb
aaaef
ccddg
ccddh
where each letter represents a different square. The lengths of the squares are completely specified by the given array.
Numberphile did a video on that which inspired me to write this challenge. He called this an imperfect square. This is code-golf so shortest code wins.
Testcases
Truthy:
[1]
[2]
[3]
[3,2,2,2,1,1,1,1]
[12,11,11,7,5,5,4,3,3,2,2,1,1]
Falsy:
[2,1]
[2,2,2]
[3,4]
[3,4]
test case. \$\endgroup\$