24
Most everyone here is familiar with Pascal's Triangle. It's formed by successive rows, where each element is the sum of its two upper-left and upper-right neighbors. Here are the first 5
rows (borrowed from Generate Pascal's triangle):
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
. . .
Collapse these rows to the left
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
. . .
Sort them in ascending order
1
1 1
1 1 2
1 1 3 3
1 1 4 4 6
. . .
Read this triangle by rows
[1, 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 4, 6 ...]
Given an input n
, output the n
th number in this series. This is OEIS 107430.
Rules
- You can choose either 0- or 1-based indexing. Please state which in your submission.
- The input and output can be assumed to fit in your language's native integer type.
- 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.
6Very nice title! – Luis Mendo – 2018-02-07T14:29:50.340
1As per the OEIS link, the only change required to generate this sequence instead of a binomial coefficient is an integer division. That certainly falls under "trivial". – Peter Taylor – 2018-02-07T14:54:03.520
5@PeterTaylor This doesn't look like an obvious dupe to me. There are many other possible approaches which can lead to interesting golfing opportunities, especially for languages that don't have a binomial built-in. – Arnauld – 2018-02-07T15:09:19.410
4@PeterTaylor I'm not convinced this is a duplicate, either. So far, the MATL, JavaScript, and Pascal answers are rather different between the two challenges. However, since my vote is a hammer-open, I won't vote as yet. – AdmBorkBork – 2018-02-07T15:13:43.653
4Totally agree with @AdmBorkBork . So count me as reopen vote. That makes 3 now. How many votes are required for reopening? – Luis Mendo – 2018-02-07T15:16:48.980