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

I want to ensure I have done all I can to configure a system's
I have done a little Django development, but it has all been in a
I have a treeview in wpf and I load it ok is all done
I have been creating an image gallery with jQuery, all is done. The images
I have done a bit of testing on this myself (During the server side
I have done a bit of research into this and it seems that the
I have done this: $ z() { echo 'hello world'; } How do I
Right so I know my code/structure is pretty messy, I've not done MVC before
Following up this question here . I finally wrote up a code generation tool
I am working through some code done by a previous developer. I'm pretty new

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.