This question already has an answer here:
- Calculate A190810 22 answers
One of the Klarner-Rado sequences is defined as follows:
- the first term is \$1\$
- for all subsequent terms, the following rule applies: if \$x\$ is present, so are \$2x+1\$ and \$3x+1\$
- the sequence is strictly increasing
This is A002977.
The first few terms are:
1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...
(\$3\$ is present because it's \$2\times1+1\$, \$4\$ is present because it's \$3\times1+1\$, \$7\$ is present because it's \$2\times3+1\$, etc.)
Given \$n\$, you must return the \$n\$th element of the sequence. You may use either 0-based or 1-based indexing. (Please specify your choice in your answer.)
input = 10 output = 22
Let's see who can get less bytes...
Also featured on codewars