I want to create a Recaman sequence where there is a "1" in the n-th position. So from which integer should I start the Recaman sequence? If there are more than one starting integer that generates a sequence with a 1 in the n-th position, return the lowest one.
For example if I want to place the digit 1 in the 7th place in the sequence then I should start the sequence from six as follow;
seq = [6 5 3 6 2 7 1 8 16]
You can also start the sequence with 12 and obtain a series where there is a 1 in 7th position;
seq = [12 11 9 6 2 7 1]
Related Challenges :
there are a few look-up table solutions here, could you please add just a few test cases to discourage this? perhaps you could also add an additional test case that uses simply something like the following: assert(~any(cellfun(@(x)ismember(max([0,str2num(x)]),[13 15 26 54 208 2485]),regexp(fileread('RecamanIII.m'),'[\d\.\+\-\*\/]+','match'))))
I have added assert line and rescored the solutions
If the nth number is 13, the Recaman sequence will end in 1 when started with 1 or 3 or 7 or 15 or continues. The test response says the answer is 15 (yes) but other answers also work. It seems like many possibilities exist for the nth number being 1.
David Hill, thanks for your interest. Lets start sequence with 15;
15 14 12 9 5 10 4 11 3 12 2 13 1
Results indicate that the index of 1 is 13. Question is asking the starting point that will generate a series where the index of 1 is in desired place (=input).
What about [1, 2, 4, 1, 5,10, 4,11, 3,12, 2,13,1] or
[3, 2, 4, 1, 5,10, 4, 11,3, 12, 2,13, 1] or
[7, 6, 4,1,5,10, 4,11,3,12,2, 13, 1]? These all start with different numbers but have a series that ends in 1 in the 13th position. It doesn't seem that the answer is unique.
David, your examples also ends in 1 in the 13th position that is right. However there are other 1s in series before 13th position. For example first example has 1 in first and 4th position. Second example also has a one in fourth position before 13th position and so on. When we start the series with 15 we obtain a series where the 1 occurs first time in 13th position.
David, upon your comments I have changed the problem statement.
David sequence examples are incorrect, the series cannot have repeated 1's (by definition, it is possible to have repeated elements but not repeated 1's). For example, the sequence starting with 1 would be [1 2 4 7 3 8 14 21 13 22 12 23 11] instead of [1, 2, 4, 1, 5,10, 4,11, 3,12, 2,13,1] as David suggests (e.g. after [1 2 4], 4-3 appears already in the sequence so it jumps to 4+3 instead)
that said, his general comment still stands that the solutions to this problem are often not unique (several different sequences will contain a 1 in the n-th position) so the problem statement perhaps should clarify that you are asking for the 'lowest integer' to start a Recaman sequence containing a 1 in the n-th position (or something along these lines)
(otherwise a perfectly valid answer would be to use a seed = 1+n^2/2-n/2 which always results in a Recaman sequence with a 1 in the n-th position)
Thanks Alfonso, I tried to clarify the problem statement!
leading solution is cheater solution: https://www.mathworks.com/matlabcentral/cody/problems/44340-recaman-sequence-iii/solutions/1391285
Find common elements in matrix rows
1174 Solvers
869 Solvers
363 Solvers
338 Solvers
271 Solvers