Hello and a warm welcome to everyone! We're excited to have you in the Cody Discussion Channel. To ensure the best possible experience for everyone, it's important to understand the types of content that are most suitable for this channel.

Content that belongs in the Cody Discussion Channel:

- Tips & tricks: Discuss strategies for solving Cody problems that you've found effective.
- Ideas or suggestions for improvement: Have thoughts on how to make Cody better? We'd love to hear them.
- Issues: Encountering difficulties or bugs with Cody? Let us know so we can address them.
- Requests for guidance: Stuck on a Cody problem? Ask for advice or hints, but make sure to show your efforts in attempting to solve the problem first.
- General discussions: Anything else related to Cody that doesn't fit into the above categories.

Content that does not belong in the Cody Discussion Channel:

- Comments on specific Cody problems: Examples include unclear problem descriptions or incorrect testing suites.
- Comments on specific Cody solutions: For example, you find a solution creative or helpful.

Please direct such comments to the Comments section on the problem or solution page itself.

We hope the Cody discussion channel becomes a vibrant space for sharing expertise, learning new skills, and connecting with others.

The Ans Hack is a dubious way to shave a few points off your solution score. Instead of a standard answer like this

function y = times_two(x)

y = 2*x;

end

you would do this

function ans = times_two(x)

2*x;

end

The ans variable is automatically created when there is no left-hand side to an evaluated expression. But it makes for an ugly function. I don't think anyone actually defends it as a good practice. The question I would ask is: is it so offensive that it should be specifically disallowed by the rules? Or is it just one of many little hacks that you see in Cody, inelegant but tolerable in the context of the surrounding game?

Incidentally, I wrote about the Ans Hack long ago on the Community Blog. Dealing with user-unfriendly code is also one of the reasons we created the Head-to-Head voting feature. Some techniques are good for your score, and some are good for your code readability. You get to decide with you care about.

Twitch built an entire business around letting you watch over someone's shoulder while they play video games. I feel like we should be able to make at least a few videos where we get to watch over someone's shoulder while they solve Cody problems. I would pay good money for a front-row seat to watch some of my favorite solvers at work. Like, I want to know, did Alfonso Nieto-Castonon just sit down and bang out some of those answers, or did he have to think about it for a while? What was he thinking about while he solved it? What resources was he drawing on? There's nothing like watching a master craftsman at work.

I can imagine a whole category of Cody videos called "How I Solved It". I tried making one of these myself a while back, but as far as I could tell, nobody else made one.

Here's the direct link to the video: https://www.youtube.com/watch?v=hoSmO1XklAQ

I hereby challenge you to make a "How I Solved It" video and post it here. If you make one, I'll make another one.

There are a host of problems on Cody that require manipulation of the digits of a number. Examples include summing the digits of a number, separating the number into its powers, and adding very large numbers together.

If you haven't come across this trick yet, you might want to write it down (or save it electronically):

digits = num2str(4207) - '0'

That code results in the following:

digits =

4 2 0 7

Now, summing the digits of the number is easy:

sum(digits)

ans =

13

I'm having problem in its test 6 ... passing 5/6 what would be the real issue..

am wring Transformation matrix correct.. as question said SSW should be 202.5 degree...

so what is the issue..

That's the question:

The file cars.mat contains a table named cars with variables Model, MPG, Horsepower, Weight, and Acceleration for several classic cars.

Load the MAT-file. Given an integer N, calculate the output variable mpg.

Output mpg should contain the MPG of the top N lightest cars (by Weight) in a column vector.

I wrote this code and the resulting column vector has the right values but it doesn't pass the tests. What's wrong?

function mpg = sort_cars(N)

load cars.mat

sorted=sortrows(cars,4)

mpg = sorted(1:N,2)

end

Thats the task:

Given a square cell array:

x = {'01', '56'; '234', '789'};

return a single character array:

y = '0123456789'

I wrote a code that passes Test 1 and 2 and one that passes Test 3 but I'm searching a condition so that the code for Test 3 runs when the cell array only contains letters and the one for Test 1 and 2 in every other case. Can somebody help me?

This is my code:

y = []

[a,b]=size(x)

%%TEST 3

delimiter=zeros(1,a)

delimiter(end)=1

delimiter=repmat(delimiter,1,b)

delimiter(end)=''

delimiter=string(delimiter)

y=[]

for i=1:a*b

y = string([y x(i)])

end

y=join(y,delimiter)

y=erase(y,'0')

y=regexprep(y,'1',' ')

%%TEST 1+2

for i=1:a*b

y = string([y x(i)])

y=join(y)

end

y=erase(y,' ' )

That's the question: Given four different positive numbers, a, b, c and d, provided in increasing order: a < b < c < d, find if any three of them comprise sides of a right-angled triangle. Return true if they do, otherwise return false .

I wrote this code but it doesn't pass test 7. I don't really understand why it isn't working. Can somebody help me?

function flag = isTherePythagoreanTriple(a, b, c, d)

a2=a^2

b2=b^2

c2=c^2

d2=d^2

format shortG

if a2+b2==c2

flag=true

else if a2+b2==d2

flag=true

else if a2+c2==d2

flag=true

else if c2+b2==d2

flag=true

else flag=false

end

end

end

end

end

Hi, I'm trying to solve this problem but I'm getting an error so far.

Problem:

Given a vector a, find the number(s) that is/are repeated consecutively most often. For example, if you have

a = [1 2 2 2 1 3 2 1 4 5 1]

The answer would be 2, because it shows up three consecutive times

What I've written so far (not done):

a = [1 2 2 2 1 3 2 1 4 5 1];

[x,y] = size(a);

counter = zeros(1,10);

if x == 1

for i=1:1:y

if a(i) == a(i+1)

counter(a(i)) = counter(a(i))+1

end

end

else

for i=1:1:x

if a(i) == a(i+1)

counter(a(i)) = counter(a(i))+1

end

end

end

But it says "error" in the line of "if a(i) == a(i+1)". I noticed that it creates a variable called "i" which value is 11, but it should create a vector from 1 to 11. What's wrong here?

I know my solution might not be in the right direction or something, but please don't tell me anything!

Thanks in advance

If a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a 6-sided die is 3.5.

Given N, simulate 1e8 N-sided dice rolls by creating a vector of 1e8 uniformly distributed random integers. Return the difference between the mean of this vector and the mean of integers from 1 to N.

function dice_diff = loln(N)

A=randi([1,N],1e8,1)

M=mean(A)

B=1:N

m=mean(B)

dice_diff =abs(M-m);

end

Here is my code, but it can't work out as it needs too long time to creat A.

I recently have found that I am no longer able to give my difficulty rating for questions on Cody after sucessfully completing a question. This is obviously not a big deal, I was just wondering if this was an issue on my end or if there was some change that I was not aware of.

The option to rate does not pop up after solving a problem, and the rating in general does not even show up anymore when answering questions (though it is visible from problem groups).

When solving problems over on Cody, I can almost always view all solutions to a problem after submitting a correct solution of my own. Very rarely, however, this is not the case, and I instead get the following message:

This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

You may solve another problem from Community group to unlock all the solutions to this problem.

If this happens, then again, I can almost always rectify this by submitting a (correct) solution to a different problem (I take it that the Community group is the implicit group of all problems on Cody --- is it?). But sometimes that, too, fails.

So my question is, why? What are the criteria that determine when all solutions are, in fact, unlocked?

I created a problem in Cody that approximates e. To test the user's solution, I compare their solution to e. What I want to do instead is compare the user's solution to my reference solution. The question is how do I call the reference solution in the test suite?

This is currently my test suite.

sol=exp(1);

y_correct = playgame();

assessVariableEqual('y_correct',sol);

Dear Sir or Madam

I tried to solve the cody-problem namend in the title.

Could you pleas tell me how I should name the vektor/variable in which it should be presentet?

Thank you for helping me.

Yours faithfully

Jann Borlinghaus