Ad
  • Default User Avatar
  • Default User Avatar

    Damn I feel dumb. Thank you for showing me how to do it better

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    The JavaScript translation uses PascalCase for the name of the function (SubtractSum), but according to JavaScript naming conventions it should be using camelCase for this (subtractSum), this should be corrected both in the default code and in the tests.

  • Custom User Avatar

    for real, most people here not excluding me decided to "damn debugging we're writing an entirely different piece of code today"

    (apologies if it seems like I was necroposting)

  • Default User Avatar

    Thank you, for explain it!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Nice mathematical challenge, well done.

  • Custom User Avatar

    Understood. So in my move count this is move 20, and the next move would be Red inserting E3, finishing the line before Yellow can. I guess I know what to fix my implementation then, thank you so much! :-))

    And of course you were right that this was no issue, it was an edge case!

  • Default User Avatar

    I think that most likely, your solution incorrectly sees a Yellow diagonal from B1 to F5 on move 21:

    move 21, F_Yellow:
    
          Y      
          R   Y  
          R   R  
        R Y   Y  
    R   Y R R R Y
    Y Y R Y Y Y R
    -------------
    A B C D E F G
    

    you should try to test your function with moves.slice(0, 21) and see the result

  • Custom User Avatar

    I see that by mapping the object with input "colors" of each move to the object with insertion number of each move, so I cannot really log the changing state in my implementation. Also, my number counts all start from 0, including the insertion, so this might mislead if I try to put that into visuals.

    Maybe I will double check again if I have any errors in my code, or try to check if there might be more random tests ahead that my function wouldn't pass either currently. I guess I took away too much time from you as well already.

  • Default User Avatar

    Yeah sorry, my function exits as soon as there is a winner, this is why not all moves were represented. I did not remember that in this kata the game can keep going even though there is a winner already. I printed the full board and it is the same as yours, so it seems like your function fails to recknognize the winner at some point. Can you print the state of the grid as soon as you detect a winner ? You wrote in your first message that you see Yellow winning at move 20.

  • Custom User Avatar

    Sure, but you have different data! Maybe my wording was the problem: My input for the function is from the third kata of the basic test, but not the third of the "first round" tests.
    The input is as mentioned above, which are all possible 42 moves, so you should not have empty slots.
    (console.log([ 'F_Yellow', 'G_Red', 'D_Yellow', 'C_Red', 'A_Yellow', 'A_Red', 'E_Yellow', 'D_Red', 'D_Yellow', 'F_Red', 'B_Yellow', 'E_Red', 'C_Yellow', 'D_Red', 'F_Yellow', 'D_Red', 'D_Yellow', 'F_Red', 'G_Yellow', 'C_Red', 'F_Yellow', 'E_Red', 'A_Yellow', 'A_Red', 'C_Yellow', 'B_Red', 'E_Yellow', 'C_Red', 'E_Yellow', 'G_Red', 'A_Yellow', 'A_Red', 'G_Yellow', 'C_Red', 'B_Yellow', 'E_Red', 'F_Yellow', 'G_Red', 'G_Yellow', 'B_Red', 'B_Yellow', 'B_Red' ].length)
    === 42)

    Here is the visualization:

    R R R Y R Y Y
    Y Y R R Y Y R
    R R Y R Y R Y
    Y Y R Y R Y R
    R R Y R R R Y
    Y Y R Y Y Y R
    -------------
    A B C D E F G
    

    Yellow wins with diagonal from B1 to G6

    Red has two "opposing" diagonals:
    One from C1 to G6, the other one in the opposing direction from G1 to B6.

    You can't see the winner from this visualization, however. The fourth move in all lines is inserted in row 4 (the first row is at the bottom in this graphic). That is why I added the insertion order before.

  • Default User Avatar

    Can you try to make a visual representation of the game board after all the moves have been played ? This is what i get:

          Y
          R   Y
          R   R
        R Y R Y
    R   Y R R R Y
    Y Y R Y Y Y R
    -------------
    A B C D E F G
    

    Red wins by completing the diagonal from D to G.

  • Custom User Avatar

    My bad, I just assumed that if someone passes 205 tests, including all random tests, but fails on a single fixed test, you would sure want to have a look at it without much ado. Will pass more data below for better justification!

    I understand that all previous solutions speak for themselves, but I thought people might also have updated the test suite, and could have introduced an error later. Is that not the case?

    Below you can see a visualization of the filled board, first with the user handles, then with the order of insertion for each coin. As you can see from the data, Yellow has one winning line, while Red has two. The fourth inserted coin of Yellow's winning line is move no. 20, while Red only inserted his with move no. 21. Yellow wins on move 20, a diagonal.

    Data:
    User handles:
    {
    row: [
    [
    'Y', 'Y', 'R',
    'Y', 'Y', 'Y',
    'R'
    ],
    [
    'R', 'R', 'Y',
    'R', 'R', 'R',
    'Y'
    ],
    [
    'Y', 'Y', 'R',
    'Y', 'R', 'Y',
    'R'
    ],
    [
    'R', 'R', 'Y',
    'R', 'Y', 'R',
    'Y'
    ],
    [
    'Y', 'Y', 'R',
    'R', 'Y', 'Y',
    'R'
    ],
    [
    'R', 'R', 'R',
    'Y', 'R', 'Y',
    'Y'
    ]
    ],
    col: [
    [ 'Y', 'R', 'Y', 'R', 'Y', 'R' ],
    [ 'Y', 'R', 'Y', 'R', 'Y', 'R' ],
    [ 'R', 'Y', 'R', 'Y', 'R', 'R' ],
    [ 'Y', 'R', 'Y', 'R', 'R', 'Y' ],
    [ 'Y', 'R', 'R', 'Y', 'Y', 'R' ],
    [ 'Y', 'R', 'Y', 'R', 'Y', 'Y' ],
    [ 'R', 'Y', 'R', 'Y', 'R', 'Y' ]
    ],
    diagonalUp: [
    [ 'R' ],
    [ 'Y', 'R' ],
    [ 'R', 'Y', 'R' ],
    [ 'Y', 'R', 'R', 'Y' ],
    [ 'R', 'Y', 'Y', 'R', 'R' ],
    [ 'Y', 'R', 'R', 'R', 'Y', 'Y' ],
    [ 'Y', 'Y', 'Y', 'Y', 'Y', 'Y' ],
    [ 'R', 'R', 'R', 'R', 'R' ],
    [ 'Y', 'R', 'Y', 'Y' ],
    [ 'Y', 'R', 'R' ],
    [ 'Y', 'Y' ],
    [ 'R' ]
    ],
    diagonalDown: [
    [ 'Y' ],
    [ 'R', 'Y' ],
    [ 'Y', 'R', 'R' ],
    [ 'R', 'Y', 'Y', 'Y' ],
    [ 'Y', 'R', 'R', 'R', 'Y' ],
    [ 'R', 'Y', 'Y', 'Y', 'R', 'Y' ],
    [ 'R', 'R', 'R', 'R', 'R', 'R' ],
    [ 'R', 'R', 'Y', 'Y', 'Y' ],
    [ 'Y', 'Y', 'R', 'R' ],
    [ 'R', 'Y', 'Y' ],
    [ 'Y', 'R' ],
    [ 'Y' ]
    ]
    }

    Insertion order:
    {
    row: [
    [
    4, 10, 3, 2,
    6, 0, 1
    ],
    [
    5, 25, 12, 7,
    11, 9, 18
    ],
    [
    22, 34, 19, 8,
    21, 14, 29
    ],
    [
    23, 39, 24, 13,
    26, 17, 32
    ],
    [
    30, 40, 27, 15,
    28, 20, 37
    ],
    [
    31, 41, 33, 16,
    35, 36, 38
    ]
    ],
    col: [
    [ 4, 5, 22, 23, 30, 31 ],
    [ 10, 25, 34, 39, 40, 41 ],
    [ 3, 12, 19, 24, 27, 33 ],
    [ 2, 7, 8, 13, 15, 16 ],
    [ 6, 11, 21, 26, 28, 35 ],
    [ 0, 9, 14, 17, 20, 36 ],
    [ 1, 18, 29, 32, 37, 38 ]
    ],
    diagonalUp: [
    [ 31 ],
    [ 30, 41 ],
    [ 23, 40, 33 ],
    [ 22, 39, 27, 16 ],
    [ 5, 34, 24, 15, 35 ],
    [ 4, 25, 19, 13, 28, 36 ],
    [ 10, 12, 8, 26, 20, 38 ],
    [ 3, 7, 21, 17, 37 ],
    [ 2, 11, 14, 32 ],
    [ 6, 9, 29 ],
    [ 0, 18 ],
    [ 1 ]
    ],
    diagonalDown: [
    [ 4 ],
    [ 5, 10 ],
    [ 22, 25, 3 ],
    [ 23, 34, 12, 2 ],
    [ 30, 39, 19, 7, 6 ],
    [ 31, 40, 24, 8, 11, 0 ],
    [ 41, 27, 13, 21, 9, 1 ],
    [ 33, 15, 26, 14, 18 ],
    [ 16, 28, 17, 29 ],
    [ 35, 20, 32 ],
    [ 36, 37 ],
    [ 38 ]
    ]
    }

  • Loading more items...