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

Learn moreOpportunities for recent engineering grads.

Apply TodayTry 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...**

11285 correct solutions
2097 incorrect solutions

Last solution submitted on Apr 20, 2014

19 players like this problem

1 Comment

Khieu
on 4 Mar 2014

What this solution is wrong?

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

1 Comment

Greg
on 9 Sep 2013

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

3 players like this solution

3 Comments

Greg
on 9 Sep 2013

What the heck is freepass?

Ramesh Vukyam
on 23 Oct 2013

Is this a solution ?

José Ramón Menzinger
on 10 Feb 2014

Nice place to test... ;-)

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.

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

1 player likes 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.

1 player likes 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)))

6 Comments