From the problem text:
(...)in this exercise it is enough to compare the number of pieces each player has on the game board. (...)
The function should return the value 1 if player 1 won, and the value 2 if player 2 won. If both players have the same number of pieces on the board, the function should return the value 0.
But the tests evaluate the comparison between the sums of ones and twos.
For example if I write the code:
def who_won(game_board: list) -> int:
p1, p2 = 0, 0
[((p1 := p1 + item) if item == 1 else (p2 := p2 + item)) for line in game_board for item in line]
return 0 if p1 == p2 else 1 if p1 > p2 else 2
the tests 3 and 4 fail:
FAIL:
GoTest: test_3_ready_made_boards
1 != 0 : The result 0 does not match with the model solution 1 when the matrice is [[1, 2, 1], [0, 0, 1], [2, 1, 0]]
FAIL:
GoTest: test_4_random_boards
1 != 2 : The result 2 does not match with the model solution 1 when the matrice is
[[1, 2, 1, 2, 2, 2, 1, 2, 1], [2, 1, 1, 2, 1, 1, 0, 0, 2], [1, 0, 0, 1, 2, 1, 0, 1, 2], [1, 1, 0, 0, 0, 0, 2, 0, 1], [1, 1, 0, 1, 0, 1, 1, 1, 1], [1, 2, 2, 2, 0, 1, 0, 1, 1], [1, 0, 1, 0, 1, 1, 2, 1, 1], [2, 1, 1, 2, 0, 2, 2, 2, 0], [0, 1, 0, 0, 1, 1, 2, 1, 0]]
Just out of curiosity I tried this code and it worked:
def who_won(game_board: list) -> int:
p1, p2 = 0, 0
[((p1 := p1 + item) if item == 1 else (p2 := p2 + item)) for line in game_board for item in line]
return 0 if p1*2 == p2 else 1 if p1*2 > p2 else 2
Which means the tests for this problem are incorrect, they check for the sums instead of the frequencies. Would you like to fix them?
https://programming-24.mooc.fi/part-5/1-more-lists - problem "Go"
From the problem text: (...)in this exercise it is enough to compare the number of pieces each player has on the game board. (...) The function should return the value 1 if player 1 won, and the value 2 if player 2 won. If both players have the same number of pieces on the board, the function should return the value 0.
But the tests evaluate the comparison between the sums of ones and twos.
For example if I write the code:
the tests 3 and 4 fail: FAIL: GoTest: test_3_ready_made_boards 1 != 0 : The result 0 does not match with the model solution 1 when the matrice is [[1, 2, 1], [0, 0, 1], [2, 1, 0]] FAIL: GoTest: test_4_random_boards 1 != 2 : The result 2 does not match with the model solution 1 when the matrice is [[1, 2, 1, 2, 2, 2, 1, 2, 1], [2, 1, 1, 2, 1, 1, 0, 0, 2], [1, 0, 0, 1, 2, 1, 0, 1, 2], [1, 1, 0, 0, 0, 0, 2, 0, 1], [1, 1, 0, 1, 0, 1, 1, 1, 1], [1, 2, 2, 2, 0, 1, 0, 1, 1], [1, 0, 1, 0, 1, 1, 2, 1, 1], [2, 1, 1, 2, 0, 2, 2, 2, 0], [0, 1, 0, 0, 1, 1, 2, 1, 0]]
Just out of curiosity I tried this code and it worked:
Which means the tests for this problem are incorrect, they check for the sums instead of the frequencies. Would you like to fix them?