Should example Output wins should be [3 4]?
I guess so.
The example should definitely be [3 4]. I can't understand why the no-wins output has to be 0 rather than  - the empty matrix would be more consistent with the requirement to list all squares. I wonder also if the list is supposed to have unique entries? The test cases don't check this.
Test 2: b=7 ?
Sorry. OK. It is X's move
Bad problem. Example solution should be [3 4].
Test suite problem.
The first test calls my function twice, with different values for (a). To test this
y function starts and endes with diagnostics:
function wins = ticTacToe(a)
disp( a )
wins = unique( wins)
The first test result is:
a = [ 1 0 0
0 -1 0
-1 0 1];
b = ;
out = ticTacToe(a);
1 0 1
0 -1 0
-1 -1 1
1 0 0
0 -1 0
-1 0 1
Empty matrix: 0-by-1
I keep getting an error while submitting my solution: "There was an issue submitting your solution. Remove inappropriate content. For guidelines, see About Cody." There is no inappropriate content in my solution.
Brendan, this may be the side effect of anti-spam filters. Try to change variable names, etc. Sometimes even adding a space here or there works.
Brendan, Jan is right. Dealing with spam is giving us a hard time. If we set the barrier too low, we get terrible inflows of spam. If we set it too high, we annoy good people like you. Sorry about the hassle. We are working on it now.
Please fix test case 1. It's somehow creating problems for the other test cases because 'a = [ ' doesn't start on a new line.
I agree with yurenchu. The test cases are broken at the moment and need to be fixed - otherwise correct solutions don't work.
, = ,
'qx' = 'qx'
@yurenchu - I fixed the test case 1 to start in a new line.
Thank you for fixing the test case!
This code is failing the first case of the test suite (instead of [4 8], only  is displayed) but passing the rest. I can't find out what is wrong in it! Any suggestions?
What's wrong in this code?
I was looking for this kind of an understandable algorithm. Thank you so much. I've got a good piece of idea now.
Why does it not work? Why does it return wrong vector 'ind' ?
That's two different questions. (1) It doesn't work because "find" returns a column vector. This can be fixed by transposing the "ind" in the "for" statement, as I've done in Solution 1276663 to this problem. (2) AFAIK, there is an unknown glitch in Cody whereby the preceding bug in your code caused the contents of "ind" to be misreported; actually the contents of your "ind" were fine, as Solution 1276663 shows.
Thanks David. Previously I did get a solution with a transposed "ind" working (see Solution 1142933). It seems at that time I just wasn't aware yet that a for-loop assigns not just scalars but whole column vectors to its index variable ('j").
However, this still leaves me puzzled about why the wrong value of "ind" is reported (*before* entering the for-loop); but this is probably indeed just a glitch in Cody or this test suite.
I don't get why I fail all tests, it works perfectly in my MATLAB.
You need (something similar to) your switch/case procedure not just for the diagonals but for the rows and columns as well; otherwise you're assigning the wrong value to wins(k) (in line 6 and line 10).
For the general case the solution would need an UNIQUE statement at the end.
Arrange vector in ascending order
Matrix which contains the values of an other matrix A at the given locations.
Add two numbers
Add offset to a signal
Find the two-word state names
Who Has the Most Change?
Find state names that end with the letter A
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office