20
2
Related OEIS sequence: A008867
Truncated triangular number
A common property of triangular numbers is that they can be arranged in a triangle. For instance, take 21 and arrange into a triangle of o
s:
o o o o o o o o o o o o o o o o o o o o o
Let's define a "truncation:" cutting triangles of the same size from each corner. One way to truncate 21 is as follows:
. . . o o o o o o o . o o o . . . o o . .
(The triangles of .
are cut from the original).
There are 12 o
s remaining, so 12 is a truncated triangle number.
Task
Your job is to write a program or a function (or equivalent) that takes an integer and returns (or use any of the standard output methods) whether a number is a truncated triangle number.
Rules
- No standard loopholes.
- The input is a non-negative integer.
- A cut cannot have a side length exceeding the half of that of the original triangle (i.e. cuts cannot overlap)
- A cut can have side length zero.
Test cases
Truthy:
0
1
3
6
7
10
12
15
18
19
Falsy:
2
4
5
8
9
11
13
14
16
17
20
Test cases for all integers up to 50: TIO Link
This is code-golf, so submissions with shortest byte counts in each language win!
1Are we to output truthy and falsy outputs or is two consistent values ok? – Post Rock Garf Hunter – 2018-03-05T19:49:59.477
@WheatWizard two consistent values are acceptable. – JungHwan Min – 2018-03-05T19:51:00.087
However much the truncations overlap, the result is equivalent to a smaller triangle with smaller truncations (if truncations can have side length 0). – Asone Tuhid – 2018-03-05T22:33:01.350