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 relatively common elements in matrix rows
Find the palindrome
Clock Hand Angle 1
Predicting life and death of a memory-less light bulb
Pi Digit Probability
Basic Monte Carlo Simulation
Delete the rows in the middle
unique with nan
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office