We are used to the term "squaring" n to mean calculating n2. We are also used to the term "cubing" n to mean n3. That being said, why couldn't we also triangle a number?
How to triangle a number?
First off, let's pick a number,
53716
.Position it in a parallelogram, whose side length equals the number of digits of the number, and has two sides positioned diagonally, as shown below.
53716 53716 53716 53716 53716
Now, we want to ∆ it, right? To do so, crop the sides that do not fit into a right-angled triangle:
5 53 537 5371 53716
Take the sums of each row, for this example resulting in
[5, 8, 15, 16, 22]
:5 -> 5 53 -> 8 537 -> 15 5371 -> 16 53716 -> 22
Sum the list
[5, 8, 15, 16, 22]
, resulting in66
. This is the triangle of this number!
Specs & Rules
The input will be a non-negative integer n (n ≥ 0, n ∈ Z).
You may take input and provide output by any allowed mean.
Input may be formatted as an integer, a string representation of the integer, or a list of digits.
Default loopholes disallowed.
This is code-golf, so the shortest code in bytes wins!
More Test Cases
Input -> Output 0 -> 0 1 -> 1 12 -> 4 123 -> 10 999 -> 54 100000 -> 6 654321 -> 91
Inspiration. Explanations are encouraged!
645321 -> 91
? \$\endgroup\$645321
instead of654321
. \$\endgroup\$