Advertisement
ErolKZ

Untitled

Apr 6th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. Task 3:
  2.  
  3. Purple vs Brown is a game played on a 2D grid that in theory can be infinite (in our case we will assume that x <= y < 1 000).
  4.  
  5. Each cell on this grid can be either Purple (represented by 1) or Brown (represented by 0) The game always receives an initial state of the grid which we will call “Generation Zero”. After that, a set of 4 rules are applied across the grid and those rules form the next generation.
  6.  
  7. Rules that create the next generation:
  8.  
  9. 1. Each Brown cell surrounded by exactly 3 or exactly 6 Purple cells will also become Purple in the next generation.
  10.  
  11. 2. A Brown cell will stay Brown in the next generation if it has either 0, 1, 2, 4, 5, 7 or 8 Purple neighbors.
  12.  
  13. 3. Each Purple cell surrounded by 0, 1, 4, 5, 7 or 8 Purple neighbors will become Brown in the next generation.
  14.  
  15. 4. A Purple cell will stay Purple in the next generation if it has either 2, 3 or 6 Purple neighbors.
  16.  
  17.  
  18.  
  19. Important facts:
  20. - Each cell can be surrounded by up to 8 cells 4 on the sides and 4 on the corners. Exceptions are the corners and the side of the grid.
  21. - All the 4 rules apply at the same time for the whole grid for the next generation to be formed.
  22.  
  23.  
  24.  
  25. Your Task:
  26. Create a program that accepts:
  27. - The size of our grid - X, Y (X being the width and Y being the height)
  28. - Then the next Y lines should contain strings (each string is long X characters) created by O`s and 1`s which will represent the “Generation Zero” state and help us build the grid
  29. - The last arguments to the program should be coordinates (X1 and Y1) and the number N.
  30.  
  31.  
  32.  
  33. (X1 and Y1) will be coordinates of a cell in the grid We would like to calculate in how many generations from Generation Zero until generation N this cell was Purple. (The calculation should include generation Zero and generation N)
  34.  
  35.  
  36.  
  37. Print your result in the console.
  38.  
  39.  
  40.  
  41. Example 1: 3x3 grid, in the initial state, the second row is all 1s. how many times will the cell (1. 0) (top center) become Purple in 10 turns?
  42.  
  43.  
  44.  
  45. 3,3
  46.  
  47. 000
  48.  
  49. 111
  50.  
  51. 000
  52.  
  53. 1,0,10
  54.  
  55. expected result: 5
  56.  
  57.  
  58.  
  59. Example 2: 4x4 grid. Input:
  60.  
  61.  
  62.  
  63. 4,4
  64.  
  65. 1001
  66.  
  67. 1111
  68.  
  69. 0100
  70.  
  71. 1010
  72.  
  73. 2,2,15
  74.  
  75. expected result: 14
  76.  
  77.  
  78.  
  79. Notes:
  80.  
  81. Try using the four fundamental OOP principles while solving the tasks, where appropriate.
  82.  
  83. No frameworks needed, use plain JAVA / C# or any other OOP capable language, without external libraries.
  84.  
  85. Use only the console for Input and output.
  86.  
  87. Implement validations of the user input.
  88.  
  89. Format the code to your preferences to improve readability.
  90.  
  91. Put comments in the code to improve readability.
  92.  
  93. Use appropriate and descriptive names when naming variables and functions.
  94.  
  95. Try avoiding code lines longer than 125 characters.
  96.  
  97. Use GitHub or BitBucket for VCS.
  98.  
  99. Start small and iterate to improve your code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement