fork 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.  
  11. std::vector<Cell> MakeVector() {
  12. std::vector<Cell> R;
  13. std::string S = ".*...**.*.***..";
  14.  
  15. for (auto& o :S){
  16. R.push_back((o == '.') ? Cell::Die:Cell::Live);
  17.  
  18. }
  19.  
  20. return R;
  21. }
  22. bool Show(const std::vector<Cell>& D) {
  23. std::cout << D.size() << ':';
  24. for (auto& o : D) {
  25. std::cout << static_cast<char>((o == Cell::Die) ? '.' : '*');
  26. }
  27. std::cout << std::endl;
  28. return true;
  29. }
  30. std::uint64_t MakeHoge(std::vector<Cell> D,std::size_t L) {
  31. std::vector<Cell> T;
  32.  
  33. for (std::size_t i = 0; i < L; i++) {
  34. for (std::int64_t j = 0; j < D.size(); j++) {
  35. if (D[j] == Cell::Die) {
  36. T.push_back(Cell::Die);
  37. continue;
  38. }
  39. if (j == 0) {
  40. T.push_back(static_cast<Cell>(static_cast<std::uint8_t>(D[j]) & static_cast<std::uint8_t>(D[j + 1])));
  41. continue;
  42. }
  43. if (j == D.size() - 1) {
  44. T.push_back(static_cast<Cell>(static_cast<std::uint8_t>(D[j]) & static_cast<std::uint8_t>(D[j - 1])));
  45. continue;
  46. }
  47. if ((D[j - 1] != D[j + 1]) && D[j] == Cell::Live) {
  48. T.push_back(Cell::Live);
  49. }
  50. else {
  51. T.push_back(Cell::Die);
  52. }
  53. }
  54. if (D == T) {
  55. return i;
  56. }
  57. else {
  58. Show(T);
  59. D = T;
  60. T.clear();
  61. }
  62.  
  63. }
  64. return L;
  65. }
  66.  
  67.  
  68. int main() {
  69. std::vector<Cell> D = MakeVector();
  70.  
  71. Show(D);
  72. auto R=MakeHoge(D, 100);
  73. std::cout << "Count:" << R+1 << std::endl;
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
15:.*...**.*.***..
15:.....**...*.*..
15:.....**........
Count:3