Try out this test problem first.

Given the variable x as your input, multiply it by two and put the result in y.

Examples:

Input x = 2 Output y is 4

Input x = 17 Output y is 34

**Press the "Solve This Now!" button below to get started...**

Show
30 older comments

Sam Nazari
on 9 Apr 2012

Why does y = bitshift(x,1); give a larger solution size than the most common answer listed so far?

Manuel Ignacio
on 6 Feb 2013

The first problem. Very easy but enough to start the Cody Game. Great game!

Adrian Dronca
on 7 Mar 2013

@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.

JeremyR
on 20 Jun 2013

Deceivingly easy start to the game!

raviraja
on 11 Dec 2013

Ha ha I got it

Ruchi Agarwal
on 13 Feb 2014

Great!

Matthew Brown
on 16 Dec 2014

I did in fact start here.

Alan Martinez
on 23 Dec 2014

Good problem for beginners.

Prita Vaidya
on 30 Nov 2015

Nice!!!

Pedro Pascual González
on 30 Nov 2015

Yeah

Brendan Hofmann
on 8 Dec 2015

cool

Acylos
on 5 Jan 2016

alright

Roberto
on 5 Mar 2016

I tried to use bitshift but I forgot it doesn't work with x<0

Daniel E. Loza Morales
on 12 May 2016

Easy starter problem. Except I was expecting Cody, to require a '.m' file upload.

Mashharar Bhuiyan
on 28 Aug 2016

very basic,very interesting indeed

pixi
on 27 Oct 2016

test

Reenu Thomas
on 13 Dec 2016

Very interesting!

Muhammad M Sahari
on 17 Dec 2016

good for newcomers

Ashley Jacob
on 17 Dec 2016

interesting

sim yoke meng
on 20 Dec 2016

interesting!

nour eddin
on 24 Dec 2016

good questionsss

Adi Zabidi
on 27 Dec 2016

1st try :)

Abubaker SHERIF
on 29 Dec 2016

like

Dixon Chen
on 29 Dec 2016

ez

Nazmi Azim Azmi
on 29 Dec 2016

GG

MAX LIM ZHENG CONG
on 30 Dec 2016

nice

Mohan Shanmugam
on 9 Jan 2017

nice

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job

Devan Rao
on 10 Jan 2017

good job

Chris Shaw
on 26 Jan 2017

nice

Oguz ERSEN
on 30 Apr 2017

good

Multiplexer
on 4 Aug 2017

ok

Adrian Quesada
on 22 Aug 2017

This is the best way to start using Cody

1 Comment

nadhirahjasri
on 20 Sep 2017 at 13:53

this is fun!

1 Comment

Adrian Quesada
on 22 Aug 2017

This is the best way to star using Cody

1 Comment

Matthias Witkowski
on 8 Aug 2017

one step at atime

1 Comment

Markus Raith
on 9 Jul 2017

Nice starter

1 Comment

Foufa.h
on 8 Apr 2017

very easy

1 Comment

Henry Lu
on 28 Mar 2017

Go ahead

1 Comment

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

very easy

1 Comment

Devan Rao
on 10 Jan 2017

easy

2 players like this solution

3 Comments

MAX LIM ZHENG CONG
on 30 Dec 2016

nice

MEI HUEI LIM
on 30 Dec 2016

nice

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

nice

2 players like this solution

2 Comments

Gerard Chen
on 30 Dec 2016

nice

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

hi

2 players like this solution

2 Comments

TAYALAN SIVALINGAM
on 29 Dec 2016

easy

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

nice

2 players like this solution

2 Comments

Nur Yashmeira Yassin
on 29 Dec 2016

:)

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job

2 players like this solution

2 Comments

Suheib Sherif
on 29 Dec 2016

This was my first!

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job

3 players like this solution

2 Comments

JAEHYUK WOO
on 13 Oct 2016

easy!!

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

10 players like this solution

2 Comments

Ravi
on 29 Mar 2016

bitshift(-3,1)
ans =
-6

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

3 players like this solution

2 Comments

Alo
on 12 Mar 2016

Nice

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

5 players like this solution

2 Comments

Abdullah Momoh
on 9 Jan 2016

Addition is used instead of multiplication as it will take a shorter amount of time to compute

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

4 players like this solution

2 Comments

Matthew Atilano
on 6 Dec 2015

It might help to put in the variable x.

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

2 players like this solution

2 Comments

Daniel Jenkinson
on 4 Dec 2015

Is there a way to make y autoupdate when you change the value of x?

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

2 players like this solution

2 Comments

Sierra McGee
on 9 Nov 2015

This is a basic solution, everyone should be able to solve this.

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

3 players like this solution

3 Comments

Ruth tannert
on 30 Sep 2015

i did it!!!

Jakub Mrowka
on 19 Sep 2016

gz

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

3 players like this solution

2 Comments

Matt Brennan
on 7 Sep 2015

Step 1 complete

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

3 players like this solution

2 Comments

korraprolu brahma
on 3 Jun 2015

trying the best

SIVAPRAKASH DANABALASINGAM
on 10 Jan 2017

good job yar

2 players like this solution

1 Comment

Alexander Wickstrom
on 28 May 2015

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

2 players like this solution

1 Comment

Sebastian Cuenca
on 26 Apr 2015

Yeah, i do it

1 player likes this solution

1 Comment

Matthew Caron
on 7 Jan 2015

This was a great starter question.

1 Comment

asdasdasd
on 26 Dec 2014

what is the correct answer??

1 Comment

Divya
on 16 Jan 2014

Is it wrong?

2 Comments

Anand Abhishek Singh
on 24 Sep 2013

how leading solution size is 0?

Clayton
on 11 Nov 2013

Probably hacked something

10 players like this solution

18 Comments

Show
15 older comments

Greg
on 9 Sep 2013

What the heck is freepass?

Ramesh Vukyam
on 23 Oct 2013

Is this a solution ?

J.R.! Menzinger
on 10 Feb 2014

Nice place to test... ;-)

Alison
on 20 May 2014

cute but ridiculous

213
on 28 Jun 2014

why it's 'freepass.please',not other words else?

Alfonso Nieto-Castanon
on 28 Jun 2014

'freepass' is just a (cute but ridiculous) hack (see problem http://www.mathworks.com/matlabcentral/cody/problems/1774-free-passes-for-everyone ). The 'please' part is because we are really polite...

Pinakin
on 20 Apr 2015

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 !

Erenca
on 29 Oct 2015

how is this even possible, solution with 0 size?

Dan Po
on 24 Sep 2016

does freepass; still work?

Mostafa
on 26 Oct 2016

"Leading Solution is 0".. Just.. How?!

Aditya Jain
on 26 Oct 2016

I rescored this solution and it failed

Alfonso Nieto-Castanon
on 26 Oct 2016

@Aditya: I do not appreciate this solution being rescored, this particular solution had historical value to me, but obviously not to you

Aditya Jain
on 26 Oct 2016

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.

Aditya Jain
on 26 Oct 2016

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.

Alfonso Nieto-Castanon
on 26 Oct 2016

Zero-score solutions have some history in Cody (see problem 42396). This solution was the only zero-score 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)

Aditya Jain
on 26 Oct 2016

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

Aditya Jain
on 26 Oct 2016

@Alfonso: I have reverted back my change :)

Alfonso Nieto-Castanon
on 27 Oct 2016

that's fantastic, thanks!

1 player likes this solution

2 Comments

ABHAY SONI
on 7 Dec 2012

can anyone tell me why this is incorrect

Ned Gulley
on 12 Mar 2013

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.

8 players like this solution

5 Comments

Show
2 older comments

Dirk Engel
on 27 Jun 2012

It works, but it's ugly :-)

Chang Ho
on 6 Aug 2012

Nice! :)

Marlies
on 16 Nov 2012

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.

Zaka
on 23 Mar 2013

does this variable "ans" overrides MATLAB's default "ans"?

David Amor
on 27 Apr 2013

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?!?

2 players like this solution

1 Comment

Justyna Zander
on 3 Apr 2012

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.

2 players like this solution

2 Comments

Jan Simon
on 26 Jan 2012

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)))

Jan Simon
on 26 Jan 2012

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)))

**Tags**

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
87 players like this problem

87 players like this problem