Statistics

Problem Statement for "TurtleGame"

Problem Statement

Hero and Jack have a rectangular board that is divided into a grid of unit square cells. Some of the cells may already be missing from the board. Turtles like to walk across their board. Each turtle will always enter the top left cell of the board and then it will walk to the bottom right cell. During the walk the turtle moves in steps, and each step must take the turtle either one cell down or one cell to the right. Obviously, a turtle cannot visit a cell that is already missing from the board. The sequence of cells visited by a turtle along its walk will be called a turtle path. We say that a board is turtle-friendly if a turtle can still complete its walk on the board. In other words, a turtle-friendly board is a board that contains at least one turtle path. In particular, note that a turtle-friendly board must contain both the top left cell and the bottom right cell. Hero and Jack are now going to play a game with their board. They will take alternating turns, with Hero being the first one to play. In each turn, the active player has to remove one cell from the board. The game continues as long as the board remains turtle-friendly. The player who causes the board to stop being turtle-friendly loses the game. You are given the String[] board that represents the initial state of the board: the character '.' represents a cell that is still present, the character '#' is a cell that has already been removed. It is guaranteed that board represents a turtle-friendly board. Return "Win" if Hero can win the game regardless of how Jack plays. Otherwise, return "Lose".

Definition

Class:
TurtleGame
Method:
getwinner
Parameters:
String[]
Returns:
String
Method signature:
String getwinner(String[] board)
(be sure your method is public)

Constraints

  • board will contain between 2 and 20 elements, inclusive.
  • All elements in board will contain the same sumber of characters.
  • Each element in board will contain between 2 and 20 characters, inclusive.
  • Each character in board will be either '.' or '#'.
  • It is guaranteed that there is at least one undestroyed turtle path.

Examples

  1. {"..", ".."}

    Returns: "Win"

    This board contains two different turtle paths. Hero has two moves that don't lose him the game: he can remove either the top right or the bottom left cell. Each of these moves will leave only one of the two turtle paths, and Jack will have no valid moves left. Jack's move will create a board that is not turtle-friendly, which means that Hero will win the game.

  2. {"...", ".#.", ".#.", "..."}

    Returns: "Lose"

    Again there are only two turtle paths. However, now they are longer. Regardless of which cell Hero removes (other than the top left and the bottom right cell), his move will create three cells that can be destroyed "for free". Since 3 is an odd number, Jack will be the one to remove the last of these three cells. In the following turn Hero will lose the game.

  3. {".##", "..#", "#.."}

    Returns: "Lose"

  4. {"....", "...#", "#...", "...."}

    Returns: "Win"

  5. {"...#.", "....#", "#....", "..##."}

    Returns: "Win"

  6. {"..........", "........#."}

    Returns: "Lose"

  7. {"...........","...........","...........","...........","....#......","...........",".......#...","...........","..........."}

    Returns: "Lose"

  8. {"....#",".#...",".#...",".#.#.",".....",".....","...#.","...#.","#...."}

    Returns: "Lose"

  9. {"..........#.......","..........#....#..","...........#...#..",".....#..#........#",".........##....#..",".....#............",".............#....","...#...........#.."}

    Returns: "Lose"

  10. {"..##............","...........#...#","........#.......","..........#.....",".....#......##.#",".............##.",".....#....#.....",".......#...#.#..",".#...........#..",".............#..","..............#.","..#.............","................",".#........#.....","#.......#.......","##..............","..#.##.........."}

    Returns: "Win"

  11. {"...",".#.","...","..."}

    Returns: "Win"

  12. {"..#.","#...","....","...#","...#",".#..","...."}

    Returns: "Win"

  13. {"...##...........","#........#......","............#...",".#..........#...","......#.........",".....#....#..#..",".....#.#...#....","......##........"}

    Returns: "Win"

  14. {"............",".........##.",".#.##...#.#.","..#.........","#.....#...##","..........#.","...#.#......","..#...#.....",".##.#.......",".......#.#..","...#..#....#",".......#..##","##...#....##","..#....##...","..#........."}

    Returns: "Win"

  15. {"...............","#.....#........","...............",".....#....#....","...............",".##............","...............","...............",".............#.","......#..#...##","...............","......#........","..........#....",".....#........."}

    Returns: "Lose"

  16. {".#..##...#.....#...","...................","......#......#.....","..................."}

    Returns: "Win"

  17. {"...",".#.","...",".#."}

    Returns: "Lose"

  18. {"..#.......##....","#.......#.......",".........#......","............#...","#.....#...#..#..","........#.......",".......#.......#","##...#...##.....","................","#....#........#.",".#......#..#....",".#...###..#.....","........#.......","#............#.."}

    Returns: "Lose"

  19. {"....#.#....#...##",".......#.##......","............#....",".................","..........#......","..#..#.#.........",".#.#...........#.","#.....#....#.....","...#....#........","..........##.....","....#............",".........#..#....",".#...#...........","..#.....#........"}

    Returns: "Lose"

  20. {"...............",".#.#.#..#..#...","#.....#...#....","...#.......#..#","......###......","........#......",".....#.#.##..#.",".##..#.#....#..","#.............#","...#...........",".#..#...#...##.","#........#.#...",".....#....#...."}

    Returns: "Lose"

  21. {".#.........#","..........#.",".#..........",".......#.##.","..#....#....","#...##...#..","..........#.","............","...#........","..##...#...#","#...........","............"}

    Returns: "Win"

  22. {".....","..##.",".....",".....",".....",".....",".....",".#...",".#...","....."}

    Returns: "Lose"

  23. {"..##.........","#...........#",".............","#..#.#....#..","........#.#..","......#...#..","..#....##....","...#.........","...#.........",".....#..#....",".....###..#..",".............","............."}

    Returns: "Win"

  24. {"...##....",".#.###...","....#....",".##...###",".#......#",".#..##..#","....#....","..#...#..","##..#....",".........","#...#....","#..#.#...","...#....#","#...##..."}

    Returns: "Lose"

  25. {"...#...",".......","......."}

    Returns: "Win"

  26. {"..................","..................","..................",".................."}

    Returns: "Win"

  27. {"...##..##..#...#.##",".#...#.#....#...##.",".###.#.....#.#.#...","...........###.#...","..#.#...#....#...#.","##.##..#...#.#.....",".#..#.#.#..#.......",".#.##..##.#.#.#..#.",".....##.....###.#..","#.#.#...#.....#....","..#...#.#####......","..#....##.##.##...."}

    Returns: "Lose"

  28. {".#..#........##..",".###.....#.#.#...","..#....#.....#...",".......#..##.##.#","#.............#..",".#.....#..###....","....##......#....","...#.#....#....##","##.######.##.....","..##....#..####..",".##.#.#..#.#..#..","..#...##..##.#...","##.#...#...#.....","#....##.....#...#",".#...#........#.."}

    Returns: "Win"

  29. {".#..#...##.#....","...#..#..#.#.#.#","##.............#","..#.#.#.#.#..#..",".#....##..#.#.#.","###....#...##.#.",".#...#....#...#.","#...#.##..#.#..#","...#..#.......#.","#.....#.#####...","..#..#........##","...##.#.###...##","#..#.#..#.#.#...","....#..#.#......"}

    Returns: "Lose"

  30. {"........#..#..","##....##...#..",".........#..#.","...##....#.#..","...##.###....#","#..##....#.#..","..##..#.#####.","#.###..###..##","......#..#....","....#...#.#..#","##...#....##.#",".##...........","...#.##...#.#."}

    Returns: "Lose"

  31. {".#..##..#..#..#.##.","..###.##..##.###..#",".....#..###....###.","#..........#...#...","....#.#..#.###...##","###.....#..#####.##",".#..#....####..###.","##....#####.#......","#..#.#.#..#..###..#","#.......#....##.#..","...#...#..###..##..","....#........##.#.#",".##.....##..#..#...","#.##.#...#...####.#","...#....###....##..","#.#...#.##.###.#.#.",".#..##..........#..","#..##..##.#.#....#.","....###...###.#....","#...#...####..#...."}

    Returns: "Win"

  32. {"........#.",".#.##.....",".##...#.#.","###.#.....","#..#.#..##","#..##.....",".###.##...","#.#.......","......#...","..##....#.",".#.#......","..##.###..","...##...#."}

    Returns: "Win"

  33. {".#.###.#...#..","..#.###...#..#","#.......#.#.#.","...#.##.##..#.","#.....#.#....#","..##..........","##.#.#........","....#.#.#..#..","..##.#.#.#..##",".####.##.#..#.",".#.#.#...#..##",".....##.#....."}

    Returns: "Win"

  34. {".#####.##.........",".......##..#...##.",".###.##..#..##...#","..#.###......#.#..",".............##...","...#.######.#.##..","..#....#.#....###.","..........###.##..","###.#....#.....##.","###.....#...#...#.","###..##......#...."}

    Returns: "Win"

  35. {"....#..##.....","#.#..#..##.###","....###.#..#..","#..##...#...#.","..###....##..#","....#.#.#####.",".##...###...##","#.........##..","...#...#.....#","#...#.##......",".#.#.#.##...#.","#.....#......#",".#.#....#..#..","###.#.#....#..","####..##...#..","..............","###..#...#.##.","...##.#....#.#","##.#..#.......","####...##.##.."}

    Returns: "Lose"

  36. {".#.#..##..#..#.....",".....#....#.#.#....",".....#..##...#.....","#..#.#..........##.","####....#....#....#","#.###..##....#....#","#..#..##.....##.##.","...##.........#....",".#.......##..#.#...","#.#......##......#.",".....#....##..#.###","......#....#..#...#","....#.#....#...###.",".#...........#...#.","##.#...#....#......"}

    Returns: "Lose"

  37. {".......#.#..#.##.","...#...#.####...#",".#.##.....#....##",".#......#.#.#..#.",".....#...#..#....","#..###..#..##.#..",".#...#..#.....#.#","#.#..#..####..##.","#.#....#........#","...##...##.#...##","...#....#.###....",".#.........#....#","#.#..............","#.#....##.#.#.#..","#.#.#...##.#....."}

    Returns: "Lose"

  38. {".#.#.......#..#.#.",".##.#...#.....#.##","..##...#.......##.",".....#.#.##.....##","#.#.#....#.##.#.#.",".........#.##.###.","...#.#.#..####.##.",".#..#.#.....#.##..",".###.....#.#..#...",".#....##...#.##.##",".##....##........."}

    Returns: "Lose"

  39. {"...###.....##..##","....#...#.####..#","...#.#......#..##",".#.....###...#.#.","....#.......#.##.","......#.........#","#.......###.#....","...#.##....#.....","...###....#......","..#..#...........",".#......#..#.....","....#..#.#..##.#.","#.#...#.###..#...","#.#.#..####.#..#."}

    Returns: "Win"

  40. {"....#...#.","........#.","....#..#..",".#......#.","..##...#.#","...#.#.#..","#....#....","..#.#.#.##",".#.#..#..#",".#..###.##",".#........"}

    Returns: "Lose"

  41. {"...##..#.#",".#....#.#.","###..##..#",".......###","#....#....","..#.....##","..##...#..","##.#.#...#","...#...#..","##..#..###","..#.......","..##..#..#",".........."}

    Returns: "Lose"

  42. {"......#..#..","....#.....#.","..#...#.#.#.",".##..#......","..###....#..",".......#....","##.#......##",".....####.#.","......###..#","...#...##...","....##.##..#",".#...##...##","#..#..#....#",".#...##.#.#.","#..#.#.##...",".#...##.#.##","#..#.....#..",".#.##......#","#........##.",".....##....."}

    Returns: "Lose"

  43. {"...#....##...#.","##...##.....#..","..........#...#",".....#..##.....",".##..#...#..#..","#..#.......##..","###....##....#.","..#..#.....#.#.","#...#.#..#.....",".....#.....#...","...#...#...#.#."}

    Returns: "Win"

  44. {"...#.##.....#..","#........##...#",".#.....#.#####.","##..#..#.#.###.","#..#......#.#..",".....#.##....#.","#.......#.#...#","##.##.###.#..#.",".###..#..#.....","#.##.####.#...."}

    Returns: "Win"

  45. {".#.#..#...##......#",".##..##....##......","...##.#.#..#.#.....","#.#..#.#.#.#####...","......#.......#.#..","#.........#...#....","...#...#...#...#...","##...#......#.....#","#.##....#....#....#","....#..#..#..#..#.#",".#..#.#.##..#.....#",".....#....#.....#.#","#..##..###...##.#..","...#.#.#.#..#.#.#..","...#.#####...#.....","####..#..#.##....##","....#..##.#.###..##","##..#...#.##....#.#","..#.#..#.#.#..#...."}

    Returns: "Lose"

  46. {".....#........###.",".##....###.......#","......##...####...","....#..#....#.....","....#..#...#.....#",".#.#.#......#.....",".#.###......###.#.","......##....##..##",".#.##.#...........",".....##..#..#.#..."}

    Returns: "Win"

  47. {".#.#..#....",".....#.#..#",".....####..","....###..#.","..#........","..#.###....","...#.#.##..","##.....#.##","...###.#...","#...##..###",".##..#..#.#","#.#.......#","###...###.#",".#.##.#....","........##.","..#....#.#."}

    Returns: "Lose"

  48. {"....#.#.#.#.#","..#..#.#...#.","##....#.....#",".#..#........",".#....####..#","#.#.......#..","##.#.....#...","#.#......###.","#..#..#....#.","...#..#......"}

    Returns: "Win"

  49. {"...#.##.......#...","..##.....#..#..###","............##...#","#..#.#....#...##.#","....#.#.#...##...#",".......#.#...##..#","##.##.#..##...####",".#....##...#..##..",".#......###.#.....",".#####......#.#.##","##..#......#.##..."}

    Returns: "Win"

  50. {"........#.#.#","..#.##...##..","..#...#....#.",".#.#.####.#.#","..##....#.#..",".#.#....#..#.","####.....#...","##....##.....","..#..####..##",".#.#..##.##..","#........##..",".#.##.....##.","...#..#.##...","..#..#.....##",".....#..##..#","......#.....#",".....#....##.","...##...#...."}

    Returns: "Win"

  51. {"...##.#.#..###.#","#...###.......##","###...#..#..####","#..##.##.#.###..","...#..###.....##","##..#..##.#.##.#","#.#...#....#.#.#","...........#..#.","...#.#.#.#.#..##",".....#.#.#.....#","..##...#...#....",".#.......##.##..",".#...#.#....#.##","#...#..#..#..##.","###.....#.#.###.",".##..........#.#","##..##.#........","..##...#.#....##","##.....#..#...##","#..#...#.##.#..."}

    Returns: "Win"

  52. {"..###...........","...#.#.#.....#..","#.#..#.#.#..#.#.","....#......#..##","..#..##.#.#.#.#.","#...##.##....##.",".....#.#####.#..",".#...##...#..#.#",".###....#....##.","..##..#.##...###","#.....#........."}

    Returns: "Win"

  53. {".##.....#.#","....##.....",".....#..#..","###.#......","##...#..#..",".....#.....",".#..#......",".#...##.##.",".......##..",".#...#..###","...#..#..##","...#.#.#.##","#..........","..#.#...##."}

    Returns: "Win"

  54. {".#.##.##.......","......#........","#.#.#.....###..",".#.#.##.....#..",".#.#..#..#.....","##.##......##..","##..#.#..##....",".#......#...#.#","....#.#.###....","##...##.....#.#","#..##.#..###..#","...#..#.....#.."}

    Returns: "Win"

  55. {"........#..#....","..##....#.#.####","...###...#.....#","#.....##.......#","#......#...#....","#..#..#..#......","....#.###.#....#","..#...###..#.#.#","#...#.##.#....#.",".##......#.#.#..","#.##..#....#....","....#.#.##.#...#","##..##.#.##.##..",".#..#.#.##.#....","...##..###......","##...#..#...#.#.",".####..#.##.##..","#.#.#..###..#...","......##..#.....",".........#.##..."}

    Returns: "Lose"

  56. {".#..###..#....",".#.......##...",".......#.#...#",".....#..#....#","#.##.###..####","#.##.#.#.....#","........##..##","........##.##.","#.......#..#..",".##.......#.##",".##.....#....."}

    Returns: "Win"

  57. {".....#####.",".....#..#.#","#.#..#.....","....####.##","#..#...##..","#...#...#..","......#.#.#","...........",".#....#.#.#","......##...","#..#.##...#",".##.....#..","#........##","...#.#.....","#.#####.##.",".#..#.#.###",".#..#......","#.#........"}

    Returns: "Lose"

  58. {".#.#....####.##.##.#",".#......##.####.#.#.","..##..###....##.....","......#.....##...##.","....###..........#..","......###..##....###",".......#......##...#","###.......#..#....#.","........#..#...#....",".#.#.#.#......#.....",".#.###......###.#...","....##....##..##.#.#","#.#................#","#..#..#.#..##.#..#.#","..#..#...#.......#..","...#..#.#.##........"}

    Returns: "Lose"

  59. {"...##..........###.","#...#.....##.##.##.","#.........#..#...#.","..##..##...#..###..",".#.#.##.###.#......","...........#...#.##","..#.#..##...#.#.##.",".#..#.###..........","...#......##.#.##..",".....#.#....#..#..#","##.#.....#..#...#..","#....#....#.##...#.","...#.#..#.#.#..###."}

    Returns: "Win"

  60. {"...", "...", "...", "..." }

    Returns: "Lose"

  61. {"....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "....................", "...................." }

    Returns: "Win"

  62. {"...#.", "....#", "#....", "..##." }

    Returns: "Win"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: