![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() ![]() |
You've all heard of the game of life right? If you haven't, head on over to ol' Wikipedia.
I stumbled across a very interesting, and difficult, programming problem. Page 12, Origin of Life) http://cemc.math.uwaterloo.ca/ccc/2006/senior.pdf The only solution I could think up was brute-force. This is due to the fact that there does not seem to be any logical way to find a board's previous setup. Each board only has one next generation, but every generation could have come from a large number of previous generations. So instead of working backwards from a setup, I worked forwards for each setup. I generated every possible 5x4 grid, by identifying the set and unset bits in every number from 1 to 1048576 (2^(5x4)). For each setup, I computed the next generation, and stored the current generation in a list of possible previous generations for the next generation. Then finally, I ran a depth first search through the backpointers, to find the closest node that contained no backpointer. Have any ideas for a better way to do it? I'd like to see what you guys and gals got. C Syntax (Toggle Plain Text)
Input File 1 4 5 2 3 2 .**** .**** .**** .**** Output File 1 Input File 2 4 5 2 3 2 **... *...* .*..* **... Output File 2 Input File 3 4 5 2 3 2 *..** *.... **..* .*.*. Output File 3 Input File 4 3 4 3 4 3 .**. .... .**. Output File 4 Input File 5 3 2 2 3 2 ** *. ** Output File 5 -1 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
Re: Conway's Game Of Life - Programming Challenge
I noticed there aren't any replies yet. But I have some added discussion material. Ideas for an improved algorithm.
It would be difficult, but much more optimal since only the setups relevant to the problem are computed. Only I'm not sure if that would work. Because previous generations can have other live cells in unadjacent cells to the next generation. Sometimes a bunch of cells can simply die out. Then I thought of a further optimization: Every setup has 3 symmetrical buddies, which will all result in next generations that are symmetrical to each other. @@.. @@.. .@.. .... ..@@ ..@@ ..@. .... .... .@.. @@.. @@.. .... ..@. ..@@ ..@@ The next generation of each of those setups will be symmetrical to each other. @@.. ..@. @@.. .... ..@@ .@.. ..@@ .... .... @@.. ..@. @@.. .... ..@@ .@.. ..@@ Therefore, only a bit over 1/4 of the generations need to be computed if we test for symmetry. Haven't yet delved completely into this idea, but there should be a very optimal way to test if the "comb" value is symmetrical. Thoughts? Last edited by Sane; Feb 3rd, 2008 at 1:14 PM. |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 882
Rep Power: 4
![]() |
Re: Conway's Game Of Life - Programming Challenge
I didn't reply because I couldn't think of an better algorithm and didn't have the time to put in any real effort.
I think, given the 5x4 size limit, computing the results for all possible layouts would be the simplest way and probably would have been best for a time limited problem. Using the mirroring would make it even faster to calculate the next-gen map. The only other idea I was toying with was trying to determine the possible parents by marking each position with the number of surrounding objects it must have had in the previous generation (possibly including itself). Then you end up with a sort of minesweeper problem to work out where the parent objects were. Just thought I'd reply to let you know that at least someone was reading this, even if there were no replies. Keep the problems coming when you find good ones, I find them interesting. Thanks. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() |
Re: Conway's Game Of Life - Programming Challenge
Thanks for the shout. I was feeling pretty lonely here.
![]() The minesweeper idea is neat. But I'm not sure how well it could work, because the number of objects it could have previously had adjacent to any square is not an exact number. It is a always less than or greater than a certain amount, rarely equal. It would make the (already difficult) challenge of a minesweeper algorithm even more complicated I think. |
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: Conway's Game Of Life - Programming Challenge
I've never heard of Conway's game of life before you mentionned. The output is rather amuzing. Here's my code with a Diehard starting pattern which will generate 129 different paterns before dying on the 130th. It's not build for speed or readability, just for fun:
c Syntax (Toggle Plain Text)
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() |
Re: Conway's Game Of Life - Programming Challenge
Hehe. Amusing huh?
![]() Quite a fascinating game. Probably the most interesting game that you can't "play". One thing you might want to think about adding is a test to see if all the cells are dead. If they are, then stop, and output how many generations the cells survived for. Edit: And while we're on the topic, here is one I invented. I like to call it "Napalm". This little devil explodes quite spectacularly out from the center, and then continues to emit small explosions, until eventually settling and leaving behind two small craters in the middle. Run at maximum speed for full effect. Copyright Sane. ![]() char inpGen[ROWS][COLS] = {
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000001000000000000000000000000000000000"},
{"00000000000000000000000010100000000000000000000000000000000"},
{"00000000000000000000000100010000000000000000000000000000000"},
{"00000000000000000000000100010000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"},
{"00000000000000000000000000000000000000000000000000000000000"}
}; |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: Conway's Game Of Life - Programming Challenge
What amazes me the most is how you can get so many complex pattern from a mere 5 units pattern. I'm trying to think of a use for this behind the scenes in a processing program but I can't wrap my head around it yet.
Here's one that does 30 different pattern before lapsing into a 3 phase oscillator that goes on forever. c Syntax (Toggle Plain Text)
|
|
|
|
|
|
#8 | |
|
Programming Guru
![]() ![]() |
Re: Conway's Game Of Life - Programming Challenge
Quote:
|
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() |
Re: Conway's Game Of Life - Programming Challenge
I just thought I'd post something I submitted to an Obfuscated Code contest, since it's related to the above few posts.
Note the "glider" embedded in the center of the code. C Syntax (Toggle Plain Text)
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. Last edited by Sane; Mar 1st, 2008 at 3:28 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|