Problem 3095. Return fibonacci sequence do not use loop and condition version 2
Solution Stats
Problem Comments

8 Comments
For some reason, I keep getting test suite errors:
L 3 (C 2933): Invalid syntax at 'error'. Possibly, a ), }, or ] is missing. L 3 (C 2933): 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).^(x1);d(2,2).^(x1)], v\[1;1]);
y = uint8(M(2,:));
end
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!
have fun!
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 Comments

1 Comment
This is a cool solution, generally speaking  but it only passes the test suite because the problem's author's first test, which is supposed to disallow use of the ^ operator, is actually bugged itself.

1 Comment
This is an EXCELLENT solution, and taught me about filter(), which I didn't know about before!

1 Comment
Not bad!

1 Comment
Can Cody not handle nested functions?

1 Comment
Not sure why this solution is not working. It runs and works when I run it on my matlab.

1 Comment
I won't judge because a lookup table is really tempting when the problem author adds a plethora of restrictions.
Problem Recent Solvers43
Suggested Problems

Find the numeric mean of the prime numbers in a matrix.
7950 Solvers

The Hitchhiker's Guide to MATLAB
3131 Solvers

Project Euler: Problem 16, Sums of Digits of Powers of Two
119 Solvers

Compute a dot product of two vectors x and y
888 Solvers

268 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!