fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <string>
  5.  
  6. enum class Cell : std::uint8_t {
  7. Die = 0,
  8. Live = 1 ,
  9. };
  10. std::vector<Cell> MakeVector2() {
  11. std::vector<Cell> R;
  12. std::string S = "*...**.*.***";// find by other person.
  13.  
  14. for (auto& o :S){
  15. R.push_back((o == '.') ? Cell::Die:Cell::Live);
  16.  
  17. }
  18.  
  19. return R;
  20. }
  21. std::vector<Cell> MakeVector() {
  22. std::vector<Cell> R;
  23. std::string S = ".*...**.*.***..";
  24.  
  25. for (auto& o :S){
  26. R.push_back((o == '.') ? Cell::Die:Cell::Live);
  27.  
  28. }
  29.  
  30. return R;
  31. }
  32. bool Show(const std::vector<Cell>& D) {
  33. std::cout << D.size() << ':';
  34. for (auto& o : D) {
  35. std::cout << static_cast<char>((o == Cell::Die) ? '.' : '*');
  36. }
  37. std::cout << std::endl;
  38. return true;
  39. }
  40. std::uint64_t MakeHoge(std::vector<Cell> D,std::size_t L) {
  41. std::vector<Cell> T;
  42.  
  43. for (std::size_t i = 0; i < L; i++) {
  44. for (std::int64_t j = 0; j < D.size(); j++) {
  45. //if (D[j] == Cell::Die) {
  46. // T.push_back(Cell::Die);
  47. // continue;
  48. //}
  49. if (j == 0) {
  50. T.push_back(static_cast<Cell>(static_cast<std::uint8_t>(D[j]) & static_cast<std::uint8_t>(D[j + 1])));
  51. continue;
  52. }
  53. if (j == D.size() - 1) {
  54. T.push_back(static_cast<Cell>(static_cast<std::uint8_t>(D[j]) & static_cast<std::uint8_t>(D[j - 1])));
  55. continue;
  56. }
  57. if (((D[j - 1] == D[j + 1]) && (D[j-1] == Cell::Live)) &&( D[j]== Cell::Die)) {
  58. T.push_back(Cell::Live);
  59. continue;
  60. }
  61. if ((D[j - 1] != D[j + 1]) && D[j] == Cell::Live) {
  62. T.push_back(Cell::Live);
  63. }
  64. else {
  65. T.push_back(Cell::Die);
  66. }
  67. }
  68. if (D == T) {
  69. return i;
  70. }
  71. else {
  72. Show(T);
  73. D = T;
  74. T.clear();
  75. }
  76.  
  77. }
  78. return L;
  79. }
  80.  
  81.  
  82. int main() {
  83. std::vector<Cell> D = MakeVector();
  84.  
  85. Show(D);
  86. auto R=MakeHoge(D, 100);
  87. std::cout << "Count:" << R+1 << std::endl;
  88.  
  89. return 0;
  90. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
15:.*...**.*.***..
15:.....***.**.*..
15:.....*.*****...
15:......**...*...
15:......**.......
Count:5