Challenge:
Given an index integer n
, either output the n
'th item in this sequence, or output the sequence up to and including index n
:
25,25,7,28,29,20,21,22,23,14,35,26,7,28,29,20,16,29,12,15,28,21,14,17,30,13,16,29,12,15,28,21,10,6,12,18,15,11,7,13,19,17,13,9,15,21,18,14,10,16,22,19,15,11,17,23,20,16,12,18,24,21,17,13,19,25,23,19,15,21,27,24,20,16,22,28,25,21,17,23,29,16,13,9,15,21,18,14,10,16,22,20,16,12,18,24,21,17,13,19
How does this sequence work?
NOTE: In this explanation, index n
is 1-indexed.
Put the numbers 1
through x
on two lines of length n*6 - 1
, where x
depends on the current iteration and the length of the numbers used, and then sum the digits of the n
'th/right-most Olympic Rings of those two lines.
The first number in the sequence is calculated as follows:
The length of the lines are 5 (because 1*6 - 1 = 5):
12345
67891(0)
Then leave the digits in an Olympic Rings pattern:
1 3 5
7 9
And sum them:
1+3+5+7+9 = 25
So n=1
results in 25
.
The second number in the sequence is calculated as follows:
The length of the lines are 11 (because 2*6 - 1 = 11):
12345678910
11121314151(6)
Then leave the digits in the second/right-most Olympic Rings pattern:
7 9 0
4 5
And sum them:
7+9+0+4+5 = 25
So n=2
results in 25
.
The third number in the sequence is calculated as follows:
The length of the lines are 17 (because 3*6 - 1 = 17):
12345678910111213
14151617181920212(2)
Then leave the digits in the third/right-most Olympic Rings pattern:
1 2 3
0 1
And sum them:
1+2+3+0+1 = 7
So n=3
results in 7
.
etc.
Challenge rules:
- When you output the
n
'th item in the sequence, you are allowed to take the input as 0-indexed instead of 1-indexed, but keep in mind that the calculations ofn*6 - 1
will then become(n+1)*6 - 1
or(n+1)*5 + n
. - Single numbers of more than one digit can be split up at the end of the first line when we've reached the length
n*5 + n-1
, so it is possible that a number with 2 or more digits is partially the trailing part of line 1, and partially the leading part of line 2.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Test cases:
Here is a paste-bin of the test cases 1-1,000, so feel free to choose any of them.
Some additional higher test cases:
1010: 24
1011: 24
2500: 19
5000: 23
7500: 8
10000: 8
100000: 25
1*5 + 1-1 = 5
? Shouldn't it be1*5 + 5 - 1 = 9
? \$\endgroup\$n=1
, son*5 + n-1
becomes1*5 + 1-1
, which in turn is5 - 0 = 5
. \$\endgroup\$n * 5 + n - 1
equal ton * 6 - 1
? \$\endgroup\$