16
1
Consider the following triangle.
1 23 456 7891 01112 131415 1617181 92021222 324252627 2829303132 33343536373 839404142434 4454647484950 51525354555657 585960616263646 5666768697071727 37475767778798081
As you probably noticed, the first row is of length 1, and each row thereafter is 1 digit longer than to the previous one and that it contains the digits of the positive integers concatenated.
You will be given an integer N. Your task is to find the sum of the digits that lie on Nth row of the above triangle.
Rules
You can choose either 0 or 1 indexing. Please specify that in your answer.
Default Loopholes apply.
You can take input and provide output by any standard mean, and in any reasonable format.
This is OEIS A066548, and this sequence is the triangle itself (except that we do not remove leading zeros).
This is code-golf, so the shortest code in bytes (in every language) wins. Have fun golfing!
Test Cases
Input | Output
0 | 1
1 | 5
2 | 15
3 | 25
4 | 5
5 | 15
6 | 25
7 | 20
8 | 33
9 | 33
10 | 43
11 | 46
12 | 64
Note that the above are 0-indexed. If you are looking for 1-indexed test cases, increment the input by 1.
On a quite unrelated note, I recently changed my profile picture and that inspired me to write this challenge.
1
n**2
isn*n
. – Mr. Xcoder – 2017-09-02T13:07:37.82369 bytes. Using Gauss' formula,
sum(range(n)) = ~-n*n/2 = (n - 1) * n / 2
– Mr. Xcoder – 2017-09-02T13:12:47.6401@Mr.Xcoder I think he does... – Erik the Outgolfer – 2017-09-02T13:21:30.987
@EriktheOutgolfer You're right, my bad – Mr. Xcoder – 2017-09-02T13:22:18.380