39
5
Consider taking some non-negative integer such as 8675309 and computing the absolute values of the differences between all the pairs of neighboring digits.
For 8675309
we get |8-6| = 2
, |6-7| = 1
, |7-5| = 2
, |5-3| = 2
, |3-0| = 3
, |0-9| = 9
. Stringing these results together yields another, smaller non-negative integer: 212239
. Repeating the process gives 11016
, then 0115
, which by the convention that leading zeros are not written simplifies as 115
, which becomes 04
or 4
, which can't be reduced any further. Summing all these values up we get 8675309 + 212239 + 11016 + 115 + 4 = 8898683
.
Let's define the Digit Difference Sum (or DDS) as this operation of repeatedly taking the digit differences of a number to form a new number, then adding all the resulting numbers to the original.
Here are the first 20 values in the corresponding DDS sequence:
N DDS(N)
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 11
11 11
12 13
13 15
14 17
15 19
16 21
17 23
18 25
19 27
Here are the first 10000 values, the graph for which is quite curious:
Especially since it looks the same when you plot it to 1000 or even 100:
(I'd call it the dentist's staircase...)
Challenge
Write a program or function that takes in a non-negative integer and prints or returns its DDS value. For example, if the input was 8675309
, the output should be 8898683
.
The shortest code in bytes wins.
dentist's staircase? – Martijn – 2015-09-20T12:47:42.323
12@MartijnR Dentist's staircase. – Calvin's Hobbies – 2015-09-20T13:14:45.627
@Calvin'sHobbies Orthodontist's staircase? – Beta Decay – 2015-09-21T16:03:16.793
1@BetaDecay Dentist's staircase. – Alex A. – 2015-09-21T17:08:42.563