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=')
disp( a )
...
wins = unique( wins)
end
------
The first test result is:
------
%%
a = [ 1 0 0
0 -1 0
-1 0 1];
b = [0];
out = ticTacToe(a);
assert(isequal(out(:), b(:)))
a=
1 0 1
0 -1 0
-1 -1 1
wins =
4 8
a=
1 0 0
0 -1 0
-1 0 1
wins =
Empty matrix: 0-by-1
Assertion failed.
-----
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!
My biggest code by size. Feel like other smaller codes are cheating a bit and I don't understand them.
How can this possibly appear on Cody as a correct solution?
This code is failing the first case of the test suite (instead of [4 8], only [4] 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.
593 Solvers
4691 Solvers
Project Euler: Problem 7, Nth prime
754 Solvers
291 Solvers
3502 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!