In honor of John D'Errico (and some recent posts about recursion in MATLAB), I bring a recursion challenger.
Here is the challenge: Create a function which uses recursion to find the index location of one number in a vector of unique numbers. Your function should take a vector, and use recursion to find the index location of a value in the vector. The function should take both of the below values as arguments. The function should not call any built-in MATLAB set functions, including:
ISMEMBER, INTERSECT, SETDIFF, UNIQUE, UNION, SETXOR.
Also, no calls to FIND or toolbox functions!
M = randperm(10^4);
V = ceil(rand*10^4) + 1;
As you can see, the value V might not be in M. In this case your function should return an empty array. Remember, you must use recursion to do the work! And no fair increasing the recursion limit beyond 500!
Here is one solution to the problem, lets see how others do it!
7 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5440
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5440
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5448
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5448
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5523
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5523
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5980
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5980
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5982
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5982
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5989
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_5989
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_8689
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/2346-hump-day-challenger-recursion#comment_8689
Sign in to comment.