It works, but it's ugly :-)
Nice! :)
Never realized that MATLAB sees a defined assignment (y = 2*x) different than no assignment (2*x => assignment to ans).
If anything, I would have guessed the second would be (slightly) more effort.
does this variable "ans" overrides MATLAB's default "ans"?
ok, i got there in the end. but it defeats the rules - there is no "y" variable when you change the template to ans = times2(x)...
how do you know what the rules are?!?
comment section gives a great info
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
assert(isequal(times2(1),2));
|
2 | Pass |
%%
assert(isequal(times2(11),22));
|
3 | Pass |
%%
assert(isequal(times2(-3),-6));
|
4 | Pass |
%%
assert(isequal(times2(29),58));
|
2240 Solvers
381 Solvers
Project Euler: Problem 8, Find largest product in a large string of numbers
315 Solvers
Create a square matrix of multiples
383 Solvers
272 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!