27
1
(Related)
Given an integer n > 1
,
1) Construct the range of numbers n, n-1, n-2, ... 3, 2, 1
and calculate the sum
2) Take the individual digits of that number and calculate the product
3) Take the individual digits of that number and calculate the sum
4) Repeat steps 2 and 3 until you reach a single digit. That digit is the result.
The first twenty terms of the sequence are below:
3, 6, 0, 5, 2, 7, 9, 2, 7, 9, 1, 9, 0, 0, 9, 6, 7, 0, 0, 6
Note: This sequence is NOT in OEIS.
I/O and Rules
- Numbers will get very large quickly, so the solution must be able to handle input numbers up to 100,000 without failure (it's fine if your code can handle past that).
- The input and output can be given by any convenient method.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Examples
n output
1234 9
3005 3
5007 5
9854 8
75849 8
100000 0
4+1 for a sequence challenge that's not in the OEIS – JAD – 2018-05-04T14:20:43.443
2
Whenever n ≤ 100000, only two iterations of steps 2 and 3 are sufficient to get the result. Can we take advantage of that or should the algorithm we choose work for larger values of n?
– Dennis – 2018-05-04T14:45:56.0272@Dennis The algorithm should work for any value of
n
. The solution posted only has to work up ton = 100000
. – AdmBorkBork – 2018-05-04T14:52:18.783@AdmBorkBork That seems like a subjective winning criteria. If you say that the algorithm only has to work up to N=100k and will only be tested up to 100k, how can you say whether or not it's "correct" for larger values? – Harry – 2018-05-04T21:28:43.173
1@AdmBorkBork Maybe just remove 100k altogether, submissions don't have to work for all possible inputs practically, only theoretically. – Erik the Outgolfer – 2018-05-04T21:41:03.753
3
Numbers will get very large quickly
no it doesn't – l4m2 – 2018-05-05T00:01:41.9073@l4m2 Not the output. But 100000 + 99999 + ... + 1 = 5000050000 is a 33-bit number, which your language of choice may or may not have trouble representing. – Dennis – 2018-05-05T01:51:21.343
Should we add this to OEIS? :) – Winny – 2018-05-05T03:40:06.750
@Dennis "quickly" usually mean exponential increasing don't it? – l4m2 – 2018-05-05T08:39:16.877