Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Recent Activity

Atsushi Ueno submitted a Comment to Solution 927544

The solution passes all tests but it is not correct.

3 hours and 4 minutes ago

Brian Moore submitted a Comment to Solution 578511

For the record, I don't recommend reading this, but here goes: My solution is function ans = add_two_numbers(varargin) system 'echo "function ans = assert(~), true;" > ./assert.m'; It works by redefining the assert() function that the test suite uses to always return true. This strategy can be used to solve any problem. Many of the leading solutions to problems are hacks like this. It's actually quite fascinating to think of ways to "cheat" the system

9 hours and 20 minutes ago

Atsushi Ueno submitted a Comment to Solution 927041

You have to define a function vecsum() like: function y = vecsum(x) y=0; for x= 0:1:10 y=x+y; end end because your answer is executed by calling function in test suite below. The function's name is decided by problem creater.

on 25 Jul 2016 at 10:56

Md.Farhad Hassan submitted a Comment to Solution 927041

can anyone please help me to find out the where is the mistake, i am a new learner .........

on 25 Jul 2016 at 10:21

Zhang Liang submitted a Comment to Solution 927012

But there seems to be a better choice. Why forgetting ismember?

on 25 Jul 2016 at 7:52

Zhang Liang submitted a Comment to Solution 578511

Why is this of size 9? The long string?

on 25 Jul 2016 at 6:42

John BG submitted a Comment to Solution 926968

please correct the test suite. Test 3 B_correct is wrong: where you test B_correct=[3 5 0 2 1] it should be B_correct=[3 2 0 5 1]

on 25 Jul 2016 at 1:30

Ethan Colaizzi submitted a Comment to Solution 926888

Nicely done!

on 24 Jul 2016 at 17:53

John D'Errico submitted a Comment to Solution 926454

I try to avoid brute force solutions, but...

on 22 Jul 2016 at 18:47

Ned Gulley submitted a Comment to Problem 189. Sum all integers from 1 to 2^n

John D'Errico wrote up some great commentary on this problem and how to go about solving it. http://blogs.mathworks.com/community/2016/07/21/numerical-analyst-john-derrico-takes-a-stroll-through-cody/

on 21 Jul 2016 at 21:54

Sasha Petrenko submitted a Comment to Solution 697657

Even though it doesn't solve the actual problem, I thought this solution was clever enough (without too many copy-pastes by others, or maybe MathWorks fixed this workaround since then) to merit explaining it. For those wondering, the line of code within the is_it_odd function does the following: 1. It does a system call to echo a single line to the standard i/o (a virtual place where programs can share/exchange their inputs and outputs). 2. The single line is in the form of a Matlab inline function, named assert(), that black-holes any inputs and always outputs the boolean 'true.' 3. The system call takes this single inline Matlab function and replaces the contents of assert.m (of whatever structure/setup for Matlab interpretation that Cody uses) with that single line. 4. Cody checks solutions with a series of assert(isequal(stuff,things)) calls, which now always evaluate to be true in this particular instance, as opposed to actually comparing if 'stuff' and 'things' are the same.

on 21 Jul 2016 at 17:18

chibole submitted a Comment to Solution 925909

Had cofused mod with % in python

on 21 Jul 2016 at 16:39

Willy Calvimontes submitted a Comment to Solution 925383

i really don't get why it is wrong lol

on 19 Jul 2016 at 23:40

James submitted a Comment to Solution 925109

Today's Cody Tip of the Day: Make sure you paste your solution into the text box BEFORE you hit submit.

on 19 Jul 2016 at 13:54

Md Sumon submitted a Comment to Solution 924994

How can I make it shorter?

on 19 Jul 2016 at 6:31

Md Sumon submitted a Comment to Solution 924745

What is the problem here?

on 18 Jul 2016 at 17:41

Daniel Zimmermann submitted a Comment to Solution 924080

Weak! My recursion solution should work just fine, but the server is unable to evaluate it properly. I'm going to count it.

on 16 Jul 2016 at 14:06

the cyclist submitted a Comment to Solution 923890

It's difficult to give much of a hint without giving away the answer. The key is that your function needs to be able to accept ANY input.

on 16 Jul 2016 at 13:29

Mir Rejaul Karim submitted a Comment to Problem 6. Select every other element of a vector

function y = everyOther(x) for i=1:length(x) if mod(x(i),2)~=0 y(i)=x(i) end end y=y(y>0) end What's wrong with this solution?

on 16 Jul 2016 at 5:57

Jonathan Perry submitted a Comment to Solution 923890

I don't quite understand what extra piece this is asking for. Could someone explain a bit more explicitly? I have test 1 correct, but test 2 failed.

on 15 Jul 2016 at 20:28

Kuruvilla Mani submitted a Comment to Problem 2114. Factorial Numbers

I cant use factorial function?

on 15 Jul 2016 at 12:41

Selvaraaju Murugesan submitted a Comment to Solution 923459

conv([x y],[1 1],'valid') will not work as it contains STRINGS !!

on 15 Jul 2016 at 8:58

lis coffey submitted a Comment to Solution 887209

unable to find the sum of all numbers in input vector, so the test set is correct. I make my solution: ' function y = vecsum(x) y = sum(x); end ' smaller? Thanks http://www.fixithere.net/sky-customer-service/

on 14 Jul 2016 at 12:06

lis coffey submitted a Comment to Solution 813568

I can't figure this out after 10+ tries. Someone please help? http://www.followthesteps.net/sky-contact-phone-number/

on 14 Jul 2016 at 12:02

Christian Fong submitted a Comment to Solution 922841

this work on matlab but not here, why?

on 14 Jul 2016 at 1:32

steph26 submitted a Comment to Solution 886480

consider using the 'sort' function !!

on 13 Jul 2016 at 13:20

tedchupig none submitted a Comment to Solution 919798

summary of this annoying problem: method size(min), invhilb 14, toeplitz 17, hankel 23, repmat with eye 24, meshgrid 25, 1-D for 28, 2-D for 31, ones assign value 36, reshape 38

on 11 Jul 2016 at 6:25

yao gang submitted a Comment to Solution 814157

The output should be logical,and it should't be char type: function tf = is_it_odd(n) x = n/2; y = floor(x); if x == y tf = false; else tf = true; end end

on 8 Jul 2016 at 13:51

Jason submitted a Comment to Solution 697657

Hi Ali, what is the workaround your speaking of? I am very confused by this solution, but I would like to understand it.

on 7 Jul 2016 at 2:10

Jan Orwat submitted a Comment to Solution 917113

You can use Gauss formula for triangular numbers. It will improve performance. It won't improve Cody size. To improve Cody size, you need hack. Popular hack is to wrap the code into regular expression. Somebody invented it to cheat scoring algorithm and it spreaded among cody submissions like a cancer. I'm not proud of this, I was using this hack too, fortunately realised that it makes no sense. Advice: don't care so much about the size, care about quality code. Most of super small solutions use some sort of cheats, you won't learn much from those.

on 2 Jul 2016 at 9:27

Jan Orwat submitted a Comment to Problem 42476. Model a falling body

Jonathan, it is unlikely to get rejected due to small error. After complaints, MathWorks/Cody Team took care about it few months ago. Based on submission times, solutions which may be yours were classified incorrect, because one of criterions is to stop simulation after reaching ground level and those solutions don't include this part.

on 2 Jul 2016 at 8:56

Jonathan submitted a Comment to Problem 42476. Model a falling body

Same problem. Correct solution is rejected due to order 1e-13 difference from expected.

on 1 Jul 2016 at 14:31

Jan Orwat submitted a Comment to Solution 917246

true, not 'true', false, not 'false'

on 30 Jun 2016 at 23:09

Guy Giesa-Wilson submitted a Comment to Solution 917246

My code works but it fails the test suite despite it giving the correct output. What's the deal?

on 30 Jun 2016 at 18:27

Matt Tu submitted a Comment to Solution 917167

LETSGOOOO

on 30 Jun 2016 at 15:47

Harish Babu Kankanala submitted a Comment to Solution 917113

How can the above solution be improved?

on 30 Jun 2016 at 13:55

John D'Errico submitted a Comment to Solution 917043

Of course, this solution use the formula from Carl Friedrich Gauss for the sum of the integers from 0 to n.

on 30 Jun 2016 at 12:03

John D'Errico submitted a Comment to Solution 916788

While the obvious solution is y = sum(1:2^x), that will fail miserably for x = 50. So the alternative is a looping solution, that generates the sum more intelligently. Here, the looping is done simply using recursion. In fact, we can even compute the exact sum for x =100, a problem that would take the brute force solution the lifetime of the universe. sum_int(sym(100)) ans = 803469022129495137770981046171215126561215611592144769253376 This done in fractions of a second, even for symbolic inputs.

on 30 Jun 2016 at 1:00

Anthony Tracy submitted a Comment to Solution 914874

Recursion is so expensive...

on 24 Jun 2016

Ned Gulley submitted a Comment to Solution 61727

I believe this is the very first use of the Ans Hack in Cody. See http://blogs.mathworks.com/community/2016/06/23/the-great-ans-hack/

on 23 Jun 2016

Thomas Bischoff submitted a Comment to Problem 42818. center of mass

Hi Katherine and William, thank you very much for your advice. When I generated the test suite I made a stupid mistake (I divided by n which is totally wrong!). Sorry for that. I hope that its correct now.

on 20 Jun 2016

Thomas Bischoff submitted a Comment to Problem 42801. means

Hello Rathin Joshi. I checked numbers and I think they are correct. The geometric mean should be (10!)^(1/10) and the harmonic mean should be 10/10th harmonic number.

on 20 Jun 2016

Jan Orwat submitted a Comment to Solution 910588

Note that "c(c==-d) = d" means that c and d must be same size or d is scalar. Moreover if d is not a scalar, then all "c==-d" must be true. This code seems to work in rare case, when one value is negative real number, and the rest are positive real numbers, but I have not tested it.

on 18 Jun 2016

Richard Zapor submitted a Comment to Problem 42877. Cellular Automaton | Rule X

The example does not match the solutions. First puzzle(30,3) has [0 1 1 0 ...] as next to last row with an expected [0 1 0]. The example shows this as [1 1 0]

on 18 Jun 2016

Jonathan Perry submitted a Comment to Solution 910588

I keep receiving 'Matrix dimensions must agree' when using c(c==-d)... it seems to work fine in matlab, but not on here. Any ideas?

on 17 Jun 2016

Matthew Stuckey submitted a Comment to Solution 906195

the problem is to see if a number is the square of another number in the vector. Although 25 is a perfect square, 5 is not included in the vector

on 15 Jun 2016

Atsushi Ueno submitted a Comment to Solution 909152

zeros are added to convert a logical to double.

on 15 Jun 2016

hubert andre submitted a Comment to Problem 42891. Differential equation and events

Thanks Tim, yes, I did a mistake in the equation, its a 2nd order.

on 14 Jun 2016

the cyclist submitted a Comment to Solution 903585

Changed test suite to deny this "solution"

on 14 Jun 2016

the cyclist submitted a Comment to Solution 66738

Changed test suite to deny this "solution"

on 14 Jun 2016