Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7128363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:07:51+00:00 2026-05-28T11:07:51+00:00

I have done all the code right and stuck with this silly thing: I

  • 0

I have done all the code right and stuck with this silly thing: I cannot mange to stop the print when the previous generation is the same as the new…so when the prints pattern is the same as the previous pattern it should stop.

I need to copy the board before calling ‘step’ and then compare the new and copied boards, and only print if it has changed
i need is to create a new variable just like i did board[], then to make a nested loop like the one in print, and inside do newboard[y][x] = board[y][x]

Please help me with this i cannot stop the print it always keep printing.
please show me your syntax

void step(int board[][WIDTH], int rows) {
    int x, y;
    int neighbors[HEIGHT][WIDTH];
    for (y = 0; y < rows; y++)
        for (x = 0; x < WIDTH; x++)
            neighbors[y][x] = count_neighbors(board, rows, y, x);
    for (y = 0; y < rows; y++)
        for (x = 0; x < WIDTH; x++)
            if (board[y][x] == 1) { /* Currently alive */
                if (neighbors[y][x] < 2)
                    board[y][x] = 0; /* Death by boredom */
                else if (neighbors[y][x] > 3)
                    board[y][x] = 0; /* Death by overcrowding */
            }
            else { /* Currently empty */
                if (neighbors[y][x] == 3)
                    board[y][x] = 1;
            }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:07:51+00:00Added an answer on May 28, 2026 at 11:07 am

    You just have to track changes. Rather trivial to do and far less work (execution/memory wise) than copying and comparing the whole array:

    int step(int board[][WIDTH], int rows) { // now returns a bool
        int x, y; 
        int neighbors[HEIGHT][WIDTH]; 
        int changed = 0; // save changes
        for (y = 0; y < rows; y++) 
            for (x = 0; x < WIDTH; x++) 
                neighbors[y][x] = count_neighbors(board, rows, y, x); 
        for (y = 0; y < rows; y++) 
            for (x = 0; x < WIDTH; x++) 
                if (board[y][x] == 1) { /* Currently alive */ 
                    if (neighbors[y][x] < 2) 
                    {
                        board[y][x] = 0; /* Death by boredom */ 
                        changed = 1; // change happened
                    }
                    else if (neighbors[y][x] > 3) 
                    {
                        board[y][x] = 0; /* Death by overcrowding */ 
                        changed = 1; // change happened
                    }
                } 
                else { /* Currently empty */ 
                    if (neighbors[y][x] == 3) 
                    {
                        board[y][x] = 1; 
                        changed = 1; // change happened
                    }
                } 
        return changed; // return the status (changed yes/no?)
    } 
    
    int main(void) {  
        int board[HEIGHT][WIDTH];  
        init(board, HEIGHT);  
        while (1) {  
            print(board, HEIGHT, WIDTH);
            if(step(board, HEIGHT) == 0) // no change
                break; // leave the loop
        }  
        return 0;  
    }  
    

    Edit:
    If wanted, you could as well count the actual changes (instead of just saying yes/no) and return the number of changes. Could would stay almost the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right so I know my code/structure is pretty messy, I've not done MVC before
I am working through some code done by a previous developer. I'm pretty new
I am working in Android. I have done almost all the work which is
I have done some programming and I have used Mercurial for source control. I
I have done up a page for eBay, I have tested it in Explorer,
This is the situation: I have an ASP.NET MVC 4 application. When I run
I'm stuck with the following scenario. It has a code smell, that I'm not
I am trying to perform a simple operation that i have done alot in
I have a computational algebra task I need to code up. The problem is
I have several divs for displaying demo boxes of graphics, and code boxes for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.