How can I solve "Microscopic Multiply" problem? [closed]


There is a programming challenge that I am trying to solve, but I cannot arrange my thoughts in it because I am still a student and a beginner in the field of programming, so I hope for your help
the question is: We want to simulate a small square surface of an area with micro-organisms (like bacteria) and how they spread every cycle of life (iteration) on this surface. This surface is 2-D, its size is n x n and each 1×1 space forms a block. Each can be empty or hold a micro-organism. Every cycle of life (iteration) the micro-organism can either leave the block (this block on the surface will become empty) or stay on the block. An empty surface can attract new micro-organisms or can stay empty.

NOTE: When a micro-organism leaves the surface, it just flies into the air and never returns. It does NOT move to any other block (this is to avoid confusion).

The rules that govern whether a micro-organism stays on its block on the surface or leaves it and that govern whether an empty block on the surface attracts a new micro-organism is as follows:

a- If a micro-organism is close to 4 or more micro-organisms it will leave the block making it empty.

b- If a micro-organism on a given block is alone or close to only 1 micro-organism the micro-organism will leave the block making it empty.

c- If a micro-organism is close to 2 or 3 micro-organisms it stays.

d- An empty space with 3 and only 3 close micro-organisms attracts a new micro-organism and it stops being empty.

Now a micro-organism is close to another micro-organism if it is within the 8-connect direction of it. The 8 directions are

  • up↑,
  • upper-right↗,
  • right→,
  • lower-right↘,
  • down↓,
  • lower-left↙,
  • left ←,
  • upper-left↖.

The following illustrations shows the close blocks to the block labelled ‘C’. The blocks around the ‘C’ block are the 8-connect directions that you should check An example of the surface, with 2 iterations and ‘M’ being a micro-organism and ‘-’ being an empty space and ‘[’ ‘]’ being a boundary (this example will be in 7×7, you are required to simulate a n x n) is as follows:

*We will also use the following colors to point your attention to the rule that applied on the block in its current iteration and made it change. The rules we are mentioning are the four mentioned above. The colors used will be:

a = leaves,

b = leaves,

c = stays,

d = attracts new one.

The output should be like this:


Please help me to write this program in C++.

Source: Windows Questions C++

2 thoughts on - How can I solve "Microscopic Multiply" problem? [closed]

  • Hello all, I was impressed with what this wonderful program offers in the field of education and research in a better way during these years in a comfortable and very helpful way for students, especially for those studying in major universities around the world. It was an honor to visit you and thank you