Problem 1. Times 2  START HERE
Solution Stats
Problem Comments

105 Comments
Why does y = bitshift(x,1); give a larger solution size than the most common answer listed so far?
The first problem. Very easy but enough to start the Cody Game. Great game!
@Sam Nazari
I guess it`s because calling bitshift makes the code size bigger. You call a function.
When there is only x*2 its 1 operation only.
Deceivingly easy start to the game!
Ha ha I got it
Great!
I did in fact start here.
Good problem for beginners.
Nice!!!
Yeah
cool
alright
I tried to use bitshift but I forgot it doesn't work with x<0
Easy starter problem. Except I was expecting Cody, to require a '.m' file upload.
very basic,very interesting indeed
test
Very interesting!
good for newcomers
interesting
interesting!
good questionsss
1st try :)
like
ez
GG
nice
nice
good job
good job
nice
good
ok
This is the best way to start using Cody
This is the best problem to start using Cody.
Instructions say to press the "Solve This Now!" button, but there is no such button...
good
grade
I submitted the following, which works in my version of matlab, but it found errors and said it wasn't valid:
function y = times2(x)
% Modify the line below so that the output y is twice the incoming value x
y = bitsll(x,fi(1));
% After you fix the code, press the "Submit" button, and you're on your way.
end
The beginning of the dream!
this is nice..
Smooth
What is the meaning of these axises
nice...
No one can solve this.
Hardest problem ever.
nice problem
a new starting
Nice problem
Nice
Nice problem for beginners
nice
Great for test, like Hello world.
Nice
good
nice
well done)
good
good
good
good
good
good
good
Good
Ans:y=x.^2;
">
test
Search for multiplication techniques on MATLAB if you can't get the answer.
multiply
nice
easy
so easy
Nice
Easy one
rly easy
almost stumped me
We can do it
nice
nice
great
Why was a function statement needed here?
The problem is simple enough but I am afraid you are losing others interest by putting a function inside the code.
A simpler code would provide the same context, but with less confusion why a function statement is given.
epic
nice!
too much fun
cool
Addicted! lol
clapped
The solution size just doesn't make sense. We need a new metric.
very good
best problem I've ever met
Easy one 😁
Very simple problem.
this was nice way to learn how to use cody
Moderately difficult questions
Nice
Good basic question
Awesome
Nice!
Reminded me of scalar multiplication in MATLAB thanks
Solid intro to Cody.
Good starting problem!
Good for starting. Anyway, it took me some time to figure out what to do.
Quite decent for entry
Good problem to start!
Really easy start to Cody challenge
Solution Comments

1 Comment
good job bud

1 Comment
EZ!

1 Comment
Don't edit this line.?

1 Comment
nice!

2 Comments
why can't be "y=2x" ????
@JunLong Li
2x makes no sense while 2*x means 2 multiplied by x

2 Comments
Very easy
nice

1 Comment
interesting

2 Comments
great
let's get it!

2 Comments
ez
good problem

1 Comment
Good basic question

1 Comment
Very Simple !!!

1 Comment
good

1 Comment
Well crafted problem!

1 Comment
I like

2 Comments
firstly, good
test

2 Comments
novice lalala...
nice

1 Comment
nice

1 Comment
easy

1 Comment
Start

2 Comments
Bugfest lmao can this program even read basic matlab? fix your shit
awesome <3

3 Comments
good!
nice one
nice!!

2 Comments
Leading solution size is 0???
don't know how the leading solution is calculated;/

2 Comments
Ach! even bigger than mine, you cheater!
bh i dont even know wtf this is...

1 Comment
this is fun!

2 Comments
This is the best way to star using Cody
!

1 Comment
one step at atime

1 Comment
Nice starter

1 Comment
very easy

1 Comment
Go ahead

1 Comment
why the leading solution size is 0

1 Comment
very easy

1 Comment
easy

3 Comments
nice
nice
nice

2 Comments
nice
hi

2 Comments
easy
nice

2 Comments
:)
good job

2 Comments
This was my first!
good job

2 Comments
easy!!
good job yar

1 Comment
This user appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sockpuppet' accounts. —DIV

2 Comments
bitshift(3,1)
ans =
6
good job yar

2 Comments
Nice
good job yar

3 Comments
Addition is used instead of multiplication as it will take a shorter amount of time to compute
good job yar
Haha, well done!

2 Comments
It might help to put in the variable x.
good job yar

2 Comments
Is there a way to make y autoupdate when you change the value of x?
good job yar

2 Comments
This is a basic solution, everyone should be able to solve this.
good job yar

3 Comments
i did it!!!
gz
good job yar

2 Comments
Step 1 complete
good job yar

2 Comments
trying the best
good job yar

1 Comment
Is it necessary to use the . after 2?
Couldn't you write y = 2*x; ?

1 Comment
Yeah, i do it

1 Comment
This was a great starter question.

1 Comment
what is the correct answer??

1 Comment
What this solution is wrong?

1 Comment
Is it wrong?

1 Comment
how do you improve this solution?

2 Comments
how leading solution size is 0?
Probably hacked something

1 Comment
So really, the name of the game is to pass only the assertion tests; as opposed to the description of the problem.
Definitely not seeing how to get a solution size 0...

24 Comments
What the heck is freepass?
Is this a solution ?
Nice place to test... ;)
cute but ridiculous
why it's 'freepass.please',not other words else?
'freepass' is just a (cute but ridiculous) hack (see problem http://www.mathworks.com/matlabcentral/cody/problems/1774freepassesforeveryone ). The 'please' part is because we are really polite...
hello Alfonso !
I'd like to know how the solution size for your solution to the 'times two' question is '0'
can you please explain ?
thanks !
how is this even possible, solution with 0 size?
does freepass; still work?
"Leading Solution is 0".. Just.. How?!
I rescored this solution and it failed
@Aditya: I do not appreciate this solution being rescored, this particular solution had historical value to me, but obviously not to you
The reason I rescored your solution is because a solution cannot have a size of 0. With respect to your comment on the historical value, I think the solution is still there and I haven't changed that. If you still believe its an error from my side, you can email ned.gulley@mathworks.com and we can discuss it further.
Another solution is that you could use your free pass trick and rescore this solution again. I just don't want the solution to have a size of 0.
Zeroscore solutions have some history in Cody (see problem 42396). This solution was the only zeroscore freepass solution (all other passing freepass solutions got a score of 100 for good reasons), so having this solution now fail the test removes its score and hence its significance. In any way, this is all fine and just a game, I just think it would be sad to see all of the other solutions in Cody that got zero, negative, maxint or other "impossible" scores being rescored for no good reason (#endofgetoffmylawnrant)
Good Point. I speak to Ned about this and discuss whether we should keep such solutions or not.
Thanks for the input and sorry for the trouble. #peace
@Alfonso: I have reverted back my change :)
that's fantastic, thanks!
Tried the freepass command on my computer, all I get is
Undefined variable "freepass" or class "freepass.please".
Also I have no idea how code size is calculated
this cheapo solutions need to be deleted, no one benefits from this or learns about matlab
Alfonso, please remove this nonsense score which prevents those of us trying to learn from actually discovering how to improve our prgramming
なるほどこんな解決策があるのか！全く参考にならない。
function y = times2(x)
y = x * 2;
end
@Admin, please remove Alfonsos score. This is meant to be about learning Matlab to solve problems, not hacking cody and allowing egotistical selfpromotion.
please update code grader system and remove solutions like this.

2 Comments
can anyone tell me why this is incorrect
I see two problems. It needs to be a function (as modeled by the template), and the input command hangs and times out when called by a web service.

12 Comments
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
comments really help! lol
David Amor, the rules specify that you have to assign it to a "y" variable. You just need to do
y = times2(x);
Great!
Hi Dirk, can you pls tell me how you got size 10 ?
To get size 10 you have to change y to ans:
function ans = times2(x)
2*x;
end
Nice solution!

1 Comment
Missing test cases:
assert(isequal(times2(0),0));
assert(isequal(times2(0.1),0.2));
assert(isequal(times2(0.000001),0.000002));
assert(isequal(times2(0.1000000000001),0.2000000000002));
assert(isequal(times2(1.0000000000000000000000000000001),2));
assert(isequal(times2(0),0));
... and a few others.

3 Comments
The test suite is weak. Please add:
assert(isequal(times2(Inf), Inf))
assert(isequal(times2(NaN), NaN))
assert(isequal(times2([]), []))
assert(isequal(times2(magic(3)), 2*magic(3)))
To focus the power of Matlab, add these tests:
assert(isequal(times2(Inf), Inf)) assert(isequal(times2(NaN), NaN))
assert(isequal(times2([]), [])) assert(isequal(times2(magic(3)), 2*magic(3)))
nice
Problem Recent Solvers78622
Suggested Problems

554 Solvers

Determine Whether an array is empty
724 Solvers

Make a random, nonrepeating vector.
6153 Solvers

Relative ratio of "1" in binary number
885 Solvers

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