Problem 3095. Return fibonacci sequence do not use loop and condition version 2
For some reason, I keep getting test suite errors:
L 3 (C 29-33): Invalid syntax at 'error'. Possibly, a ), }, or ] is missing. L 3 (C 29-33): Invalid syntax at 'error'. Possibly, a ), }, or ] is missing.
Hi M.C., in this problem some of the functions are banned by author. This cause "standard" solutions known from previous fibonacci numbers related problems to fail. Examine your code against functions and operators listed in 1st test.
Thanks Jan. I would have expected to receive the message "No fancy functions!" if was using something I shouldn't be. Here is my solution (which works in my matlab and doesn't appear to have anything "illegal"):
function y = fib(x)
[v,d] = eig([1 1; 1 0]);
M = v*bsxfun(@times, [d(1,1).^(x-1);d(2,2).^(x-1)], v\[1;1]);
y = uint8(M(2,:));
Ok, I see - I'm not allowed to use ^. The list of banned functions seems much more restrictive than not using a for or a conditional. Back to the drawing board!
The problem has way more restrictions than described. We cannot even use round, fix, ceil or floor, which is a pain (almost prohibiting approx. methods). In such cases, It is probably better that the author states what is the method that he is looking for.
Btw, stating which method or function to use only makes a problem easier for people that already know it, which means that they are not learning something new. And that is still true regardless of whether people know it or not. Someone that know the required method will try everything they know and will solve the problem, while someone that doesn't know the required method will also try everything, but will be stuck after emptying their options (and may do some research, give up, or cheat*). If we want to estimulate learning (avoiding the unwanted alternatives), revealing the method may help so that people don't give up. Of course, it is also possible to give some tips or a link.
* Cheating is the prefered choice at Cody and probably also in real life.
I totally agree with Rafael
Solution CommentsShow comments
Problem Recent Solvers47
Magic is simple (for beginners)
Pernicious Anniversary Problem
More from this Author17
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!