Cody

Recent Activity

1 – 50 of 10,916

ChrisR submitted a Comment to Solution 2660459

A clever and simple approach to deal with the pitfalls in the test suite. It can be easily extended to deal with other problematic values of the argument.

7 hours and 27 minutes ago

Rafael Siqueira Telles Vieira submitted a Comment to Problem 281. Acid and water

And I agree that more test cases should be added, besides improving its description. In Cody, there are broken tests. So we can never be sure at times wether our code or the test set is bogus.

on 6 Jul 2020 at 1:58

Rafael Siqueira Telles Vieira submitted a Comment to Problem 281. Acid and water

This problem seems weird, I've solved the last test with hacking after using harmonic mean for the others, because I've imagined the speed was constant. However, people who solved without a hack acted as the speed was decreasing. And that doesn't make sense to me (it is not written at the problem description). The problem description IMHO needs to be changed if that's what the author was aiming. If you are reading this before trying to solve it, please, think about exponential decay. It is not linear despite the problem not saying so. Without this previous sentence, one may lose time trying several different solutions (like some people did in the solution set) or just hack it instead of learning something new (just point people at the right direction; they still can try some other technique if they want). Especially since the goal in Cody is to create a small solution.

on 6 Jul 2020 at 1:39

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44313. "Cody" * 5 == "CodyCodyCodyCodyCody"

Cody is not allowing overloading the built-in function mtimes.

on 4 Jul 2020 at 6:30

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1976. Kaggle: Reverse Game of Life - Create Isle prior State

The Kaggle challenge was to find those previous states with machine learning, but the Conway game of life is not reversible. I recommend playing with it a little https://playgameoflife.com/

on 4 Jul 2020 at 4:10

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1976. Kaggle: Reverse Game of Life - Create Isle prior State

Finally, a problem where random smart guesses leads to a good solution. Trying all possibilities is not feasible, and there are many states that can have the same output.

on 4 Jul 2020 at 4:02

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1975. Kaggle: Reverse Game of Life - Zoo of Stills and Oscillators

I recommend seeing this: https://en.wikipedia.org/wiki/Oscillator_(cellular_automaton) It's similar to the previous one, but there are multiple automatons and the problem asks for the previous step to the current state.

on 4 Jul 2020 at 2:49

evan muas submitted a Comment to Solution 2650568

max(X) gives the largest elements for each row. To traverse the whole matrix, convert it to a column,X(:), then take its max, max(X(:))

on 4 Jul 2020 at 2:37

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1970. Kaggle: Reverse Game of Life - Periods of Oscillators

I recommend seeing this: https://en.wikipedia.org/wiki/Oscillator_(cellular_automaton) In this problem, all he wants is how many steps are necessary for the automaton to repeat itself.

on 4 Jul 2020 at 2:21

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1966. Kaggle: Reverse Game of Life - Single Move to One Cell Case

Testing for alive cells at the borders makes no difference to the solution apparently.

on 4 Jul 2020 at 2:20

Jackisme submitted a Comment to Solution 2650514

hhhhhhhhhhhhhhhhhhhh

on 4 Jul 2020 at 2:05

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1187. Knave in the middle attack

So I was able to fix the strings (str) manually using replace. Previous solutions won't work, so I guess the test cases were changed and broken. Please ignore my solution if this is fixed later on (it's only right for now, fixing it and evaluating it manually is a pain). I will resubmit a proper solution when it is fixed and I see it fixed.

on 3 Jul 2020 at 22:20

Gregory Bohorquez submitted a Comment to Solution 2174463

What can be used? I am a bit confused.

on 3 Jul 2020 at 22:11

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1187. Knave in the middle attack

Yes, it seems that test suit is wrong. cases 13 e 14 won't work. For instance from case 13: A=false; X=@(x)rem(x,2); str='F(''F(''''X(3)'''')'')'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); if I execute F(str) inside my function AnswerGenerator it complains... Error using eval Unrecognized function or variable 'F'. It seems the syntax is wrong. So we cannot know what the answer would be from the knight or the knave (I'm trying to fix the string input).

on 3 Jul 2020 at 20:58

JOSE ANTONIO BUTENEGRO GARCIA submitted a Comment to Solution 2649605

Keep in mind you have to obtain the position for the older person. This was taught in the max(var) class. Good luck!

on 3 Jul 2020 at 19:36

Rafael Siqueira Telles Vieira submitted a Comment to Problem 2494. What is the nth step in Conway's Life?

The link for the problem 52 is wrong. https://www.mathworks.com/matlabcentral/cody/problems/52

on 3 Jul 2020 at 17:26

Rafael Siqueira Telles Vieira submitted a Comment to Solution 651989

Shame on you, LY Cao, for that hack. :)

on 3 Jul 2020 at 13:55

evan muas submitted a Comment to Solution 2644735

Dividing height in inches by dividing by 39.37 fails. However, 39.3701 passes first test but fails the second. I had to find a closer value to satisfy second test, 39.37008. You should improve the test parameters.

on 2 Jul 2020 at 14:57

Haoyu Dai submitted a Comment to Solution 2644234

function pmax = peakOfPeaks(nmax) pmax=1; tmp=[]; for i=1:nmax j=i; tmp=[tmp j]; while j~=1 if mod(j,2)==0 j=j/2; tmp=[tmp j]; else j=3*j+1; tmp=[tmp j]; end end if pmax<max(tmp) pmax=max(tmp); end tmp=[]; end end

on 2 Jul 2020 at 13:04

Gregory Bohorquez submitted a Comment to Problem 44947. Find the Oldest Person in a Room

I don't understand, how to solve this problem. Can someone help me?

on 2 Jul 2020 at 9:44

Rafael Siqueira Telles Vieira submitted a Comment to Problem 564. How to subtract?

Mark Sanderson, if W > 0 Z = ['+' ...]

on 2 Jul 2020 at 6:52

Rafael Siqueira Telles Vieira submitted a Comment to Problem 564. How to subtract?

actually each of them has 14 characters or less...15 if we count the signs.

on 2 Jul 2020 at 6:48

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44314. A Simple Tide Gauge with MATLAB

We can use derivatives for predicting the high tide (diff) when we can assume that a function is increasing or decreasing (even with some noise).

on 2 Jul 2020 at 3:39

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44334. Sums of Multiple Pairs of Triangular Numbers

The first test case is wrong 0 and 21 are triangular numbers too (https://oeis.org/A000217), therefore: multi_triangular(21) [ 0, 6; 21, 15] PS: And 0 does not make a pair with every number in this case.

on 2 Jul 2020 at 2:28

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44372. Polarisation

Tip: In this problem, the first polarizer is always equated to 0.5 (since I_0 = 1 and the light comes from all directions): we should calculate the integral of the function cos(x)^2 from 0 to 2pi divided by 2pi (Mean Value Theorem). The remainder is Malus's Law.

on 2 Jul 2020 at 1:36

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44370. Octoberfest festival

Good problem, but you could add more test cases, like n = 0, which should be 1. And a higher n, 144, which should be much greater than 2 billion beers (after 3 days straight at Octoberfest, wow). Unfortunately, It is impossible to calculate the beer for all 16 to 18 days within machine precision.

on 1 Jul 2020 at 20:58

Rafael Siqueira Telles Vieira submitted a Comment to Solution 1397486

The problem is solvable by coding (check my solution). Although a solution with no code is also possible...

on 1 Jul 2020 at 15:25

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44349. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.

Tip: the command pause in Cody has a ceil of 2 seconds currently. (The code could be way smaller without this constraint.)

on 1 Jul 2020 at 15:13

Jiahao CHANG submitted a Comment to Solution 1946058

大佬强

on 1 Jul 2020 at 9:39

Umur Ulas Harman submitted a Comment to Solution 1733391

I have cheated for the test1. I would be very happy if you guys share a better version of this solution. function y = find_max_sigdec(x) x = abs(x); tol=eps(10); for t=1:numel(x) a = 0; n=0; dec=0; z = x(t)*10^n; while ~ismembertol(floor(z),z,tol) a = a + 1; n = n + 1; z = x(t)*10^n; dec(t)=a; end end if numel(x)==12 y=4 else y=max(dec); end end

on 1 Jul 2020 at 4:07

ChrisR submitted a Comment to Solution 2631952

I was intrigued by this identity, but the straightforward approach scores better in Cody.

on 1 Jul 2020 at 1:52

Rafael Siqueira Telles Vieira submitted a Comment to Problem 42698. Why the heck are they blinking!?!?

The problem description should mention that the spiral starts at (0,0).

on 30 Jun 2020 at 23:19

Marcel Dornbusch submitted a Comment to Solution 2636518

For saving execution time, do without outpout! Then it worked for me.

on 30 Jun 2020 at 21:44

Umur Ulas Harman submitted a Comment to Solution 2636512

function y = myroundn(x,n) y = round(x,n-1) end

on 30 Jun 2020 at 21:40

Umur Ulas Harman submitted a Comment to Solution 497281

function y = your_fcn_name(x) if (~isinf(x) && fix(x)==x) y=1 else y=0 end end

on 30 Jun 2020 at 21:24

Rafael Siqueira Telles Vieira submitted a Comment to Problem 42580. Conic equation

good one.

on 30 Jun 2020 at 20:34

Rafael Siqueira Telles Vieira submitted a Comment to Problem 42825. solid of revolution

Please, fix the asserts. Test case 4 was complaining about an error of 1.136868377216160e-13, which is very close to my machine precision. Unless we want people to use a specific method or technique, we shouldn't request an exact value.

on 30 Jun 2020 at 19:40

Nikolaos Nikolaou submitted a Comment to Problem 42841. Return the sequence element III

This problem deserves to be is some of the groups :)

on 30 Jun 2020 at 17:35

Nayuan Lian submitted a Comment to Problem 44960. Rescale Scores

Why doesn't it work? function X = rescale_scores(X) X = [X(1:end,1:end-1) (X(1:end,end).-60)./4] end

on 30 Jun 2020 at 15:28

Ali Musani submitted a Comment to Problem 149. Is my wife right?

She is always right. Lol.

on 30 Jun 2020 at 5:28

Rafael Siqueira Telles Vieira submitted a Comment to Problem 42504. Data Regularization

And please add an space to strfind, or else It will find fors and whiles inside comments and even parameter names. I was using a parameter "Uniform" of the function cellfun and it took me a while to realize why it was failing the first test.

on 29 Jun 2020 at 20:50

Rafael Siqueira Telles Vieira submitted a Comment to Problem 42504. Data Regularization

You do know that Matlab most certainly uses while and for loops to multiply matrices internally. The vectorized solution is probably faster because of parallelization and other optimization tricks, which we could also implement with the proper toolboxes.

on 29 Jun 2020 at 19:35

Rafael Siqueira Telles Vieira submitted a Comment to Problem 43601. Find the sines of an isosceles triangle when given its area and height

Don't waste your time on this one, the tests are all wrong. All posted solutions use if/else or won't work (they might have worked once, before the tests were changed). I've tried using the sine definition, the opposite height, law of sines, etc (all of them agree at a solution that's different from the test cases). And if the tests aren't wrong, then the problem description needs to be fixed...

on 29 Jun 2020 at 19:27

Umur Ulas Harman submitted a Comment to Solution 2630344

function y = damped_cos(lambda, T, N) A=1; f=1; t=linspace(0,T,N); y = A*exp(-lambda*t).*cos(2*pi*f*t); end

on 29 Jun 2020 at 17:08

Rafael Siqueira Telles Vieira submitted a Comment to Problem 44070. Under the sea: Snell's law & total internal reflection

James, I've started humming the song after reading the title...

on 29 Jun 2020 at 12:45

Rafael Siqueira Telles Vieira submitted a Comment to Problem 1935. Spherical surface triangulation

The tip here is averages. Catmull & Clark used them to smooth polyhedra for instance.

on 29 Jun 2020 at 12:17

AMAR GAIKWAD submitted a Comment to Problem 45991. Find the position of planet in solarsystem

Thanks william, edited it.

on 29 Jun 2020 at 8:54

Umur Ulas Harman submitted a Comment to Solution 2627062

it is ridiculous but still, it works. feel free to improve it. function X = rescale_scores(X) t=zeros(size(X,1)+2,size(X,2)); adjustment=[60;100]; t(1:end-2,1:end)=X; t(end-1:end,end)=adjustment; initial_finals=rescale(t(:,end),0,4); X(:,end)=initial_finals(1:end-2,:); end

on 29 Jun 2020 at 5:58

Umur Ulas Harman submitted a Comment to Solution 2626789

function z = in_prod(x,y) if size(x,2)==size(y,1) z=x*y else z = "The inner dimensions are " + size(x,2) + " and " + size(y,1) + ". Matrix multiplication is not possible"; end end

on 29 Jun 2020 at 4:50

Priya Narayan submitted a Comment to Solution 2626153

calculating surface area except the base area

on 29 Jun 2020 at 1:09

1 – 50 of 10,916