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.
Can Cody not handle nested functions?
Not sure why this solution is not working. It runs and works when I run it on my matlab.
I won't judge because a lookup table is really tempting when the problem author adds a plethora of restrictions.
letter yes yes & letter no no
Getting the indices from a vector
How long is the longest prime diagonal?
Multiples of a Number in a Given Range
Put m balls into n boxes
Generate a vector like 1,2,2,3,3,3,4,4,4,4
Find the maximum two numbers of every column of a matrix
Project Euler: Problem 14 Longest Collatz sequence(harder version)
Seperate array to small section according to its index position
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