6
1
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.)
Your task
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.)
0-indexed example:
input = 10
output = 22
Let's see who can get less bytes...
Also featured on codewars
Why is this tagged [javascript]? Is this restricted to it? How is this related to array manipulation and linear algebra? Does "ordered with <" mean "ascending"? – my pronoun is monicareinstate – 2019-10-11T11:46:30.113
Apart from the arbitrary language restriction there isn't any problem. – user202729 – 2019-10-11T11:59:45.473
https://codegolf.meta.stackexchange.com/a/8058/69850 -- you can "look at the challenge as a separate competition in each language". – user202729 – 2019-10-11T12:02:38.607
@Arnauld and what's with that? I solved the problem but I want to see community's inventions – maryrio7 – 2019-10-11T12:29:50.220
5@user89702 It's not yours, so you can't post it, especially without any attribution. – my pronoun is monicareinstate – 2019-10-11T12:30:22.203
Why so strict? Is just a challenge, if you don't want to participate just ignore this post, let people have fun – maryrio7 – 2019-10-11T12:31:36.980
2
However, I do believe this is a rather interesting challenge that would be worth rephrasing properly for Code Golf. There's nothing wrong on posting a challenge about this sequence (which is A002977, btw), but you can't copy from an external site without any authorization or credits.
– Arnauld – 2019-10-11T12:38:45.437I want to agree with @user89702. Two of my top posts are not my challenge, but they get upvotes. – HighlyRadioactive – 2019-10-11T12:42:56.993
1I've rephrased your post so that it better fits our standard and is not a copy of codewars anymore. Feel free to edit further if needed. – Arnauld – 2019-10-11T13:36:56.840
closely related – nimi – 2019-10-11T14:09:17.957
Currently this needs to mention that this sequence is in ascending order. Without it the only term that we can know the location of is the first one. – Post Rock Garf Hunter – 2019-10-11T18:30:29.127
I upvoted & closed as a duplicate (even though slightly different). This could get reopened if people think the offset difference is enough to make answers not trivially portable. – Jonathan Allan – 2019-10-11T20:17:52.920
How do we define duplicate? This question: If x occurs in the sequence, then 2x+1 and 3x+1 also exists. Claimed duplicate:If x occurs in the sequence, then 2x+1 and 3x-1 also exists. Are the two definitions sufficiently close to count as a duplicate. Rules Committee???? – Graham – 2019-10-11T20:50:51.187
I made the comment above as it is exceedingly frustrating to spend the time to answer a question only to find some considerable time later it is claimed to be a duplicate. Personally I do not have the time or inclination to validate every question before answering it. – Graham – 2019-10-11T21:07:43.247
2@Graham, if you've taken the time to work up a solution then absolutely post it to the dupe target. If your solution cannot be trivially modified to fit the dupe target then you have a case to reopen this one and you should cast your vote accordingly. – Shaggy – 2019-10-12T00:38:36.177