20
3
A triangular number is a number that can be expressed as the sum of consecutive positive integers, starting at 1. They can also be expressed with the formula n(n + 1) / 2
, where n
is some positive integer.
A number's digitangular counterpart is calculated in the following way:
- Split a number into an array of its digits e.g.
613 => [6 1 3]
- For each number in the array, calculate the
n
th triangular number;[6 1 3] => [21 1 6]
- Sum the resultant array;
[21 1 6] => 28
Your task is, given an integer n
, repeatedly calculate n
's digitangular counterpart, until the result is equal to 1, then output all values that were calculated. You may output the values in any order, and with an optional inclusion of the original number at the start of the array. This is a code-golf so the shortest code wins.
Test cases
23 => 9 45 25 18 37 34 16 22 6 21 4 10 1
72 => 31 7 28 39 51 16 22 6 21 4 10 1
55 => 30 6 21 4 10 1
78 => 64 31 7 28 39 51 16 22 6 21 4 10 1
613 => 28 39 51 16 22 6 21 4 10 1
8392 => 90 45 25 18 37 34 16 22 6 21 4 10 1
11111 => 5 15 16 22 6 21 4 10 1
8592025 => 117 30 6 21 4 10 1
999999999 => 405 25 18 37 34 16 22 6 21 4 10 1
1May we include the original number as first in the resultant array? – Uriel – 2017-11-21T23:28:43.737
1How do we know it always goes down to 1? – Simply Beautiful Art – 2017-11-21T23:50:04.050
@SimplyBeautifulArt Well, I've tested every integer from 1 to 10000, and all have reached the same pattern that eventually leads to 1. I can't be bothered to write a proof, but if you can find an integer that doesn't, tell me and I'll edit that into the question. – caird coinheringaahing – 2017-11-21T23:54:57.300
5Let's suppose that a number is larger than
141
and hasn
digits. The maximum value its digitangular counterpart can have is45n
, sodigi-△(x) ≤ 45n < 45(1+log_10(x))
, and forx > 141
, we have45(1+log_10(x)) < x
, hencedigi-△(x) ≤ x-1
forx > 141
, and once we pass the141
limit, well, we brute force prove via programs. – Simply Beautiful Art – 2017-11-22T00:02:55.717@SimplyBeautifulArt Shouldn't it be stated that
digi-△(x) ≤ 45n ≤ 45(1+log_10(x))
since45n = 45(1+log_10(x))
for anyn
-digit numberx > 141
that is a power of10
? – R. Kap – 2017-11-22T02:52:31.670Oh, you're right. A tad too late to edit + it happily doesn't affect my analysis of this sequence. – Simply Beautiful Art – 2017-11-22T02:53:26.630
@R.Kap Also, we could more nicely write
n = ⌊1+log10(x)⌋
, for anyx
. – Simply Beautiful Art – 2017-11-22T02:56:27.567Interestingly, it seems as if the sequence always ends with
6 21 4 10 1
. I don't know how to rigorously prove this for all the natural numbers though. – R. Kap – 2017-11-22T03:55:48.853I have 13 bytes in Jelly - Outgolfed :^) – Mr. Xcoder – 2017-11-22T05:26:28.883
@Mr.Xcoder As usual, I overthought it :P – caird coinheringaahing – 2017-11-22T05:55:13.630
The wording of the question implies that we can't start output until after the calculation is completed. Is that intentional? Or should "then" be merely "and"? – Toby Speight – 2017-11-22T09:33:21.197
1Can I have trailing 1's at the end of my output? – Simply Beautiful Art – 2017-11-22T12:10:10.840
@R.Kap Trivially, it won't. Consider
1en, 4en, or 6en
for any naturaln
. (really bad scientific notation) – Simply Beautiful Art – 2017-11-22T12:16:13.2731
Related: Digitangular numbers, seeking alternative proofs that this sequence goes to 1 eventually.
– Simply Beautiful Art – 2017-11-22T12:33:53.403@SimplyBeautifulArt Huh, that's pretty cool. That's two of my challenges where people are seeking proof that they work for given numbers – caird coinheringaahing – 2017-11-22T15:05:30.967
@TobySpeight You may output at any point of the execution of the program, be that at the start (somehow), the middle or the end – caird coinheringaahing – 2017-11-22T15:06:17.613
@SimplyBeautifulArt As in more than a single one? If so, then no, as your program doesn't terminate when it reaches one. – caird coinheringaahing – 2017-11-22T15:06:47.797