ionreq / GoLreverse

calculate previous generations for Conway's Game of Life
1 stars 0 forks source link

WS FULL even at size 999999999 kb for a 5x7 block #1

Closed jeancaffou closed 11 years ago

jeancaffou commented 11 years ago

I'm trying to get the previous generation for block: b←(7 5⍴⍳35)∊7 8 9 12 14 17 18 19 24 27 28 29

I am using workspace size of 999999999, setting it to more than this would crash Dyalog on start, so that I would have to reinstall it to reset all preferences.

Is there any way to optimize the code? Maybe stop execution when one solution is found? I would, if I could, but the APL code... It's all greek to me :)

ionreq commented 11 years ago

Hi Jean,

did you already have a look at this

http://nbickford.wordpress.com/2012/04/15/reversing-the-game-of-life-for-fun-and-profit/

?

I read the article and watched the video, but never downloaded or tried his program. Did you?

Meanwhile, I'm trying your configuration out. Will mail again when I can say more.

Stephan

ionreq commented 11 years ago

The previous generation is this:

1 0 0 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 0 1 0 0 0 0

I had the same problem as you. What I've done is simply let the colums be processed first, then the rows. I switched the appropriate code blocks around. You can do that simply in the editor, you see the two :Repeat ... :Until blocks? Just copy one of them in front or behind the other. Can you do that? Otherwise I can send you a changed source code...

Stephan

jeancaffou commented 11 years ago

Hey, thanks for the quick reply and the link, I will give it a look.

I did what you said and got the same solution as you, however testing the solution on my simple flash app here http://kafol.net/test/life/

did not generate the next (=original) generation. Huh. Are the rules on the edges different? I treat cells outside the edge as 0.

jeancaffou commented 11 years ago

It kind of looks like the original, but doesn't have the dead-cell padding around it

back to original

ionreq commented 11 years ago

Yeah, yeah, I have implemented periodic boundary conditions. And you can emulate your boundary conditions with a padding, right. Does it work satisfactorily with padding?

Thanks for your feedback, I am currently updating my readme.md on github to explain this.

Will have a look at your app later.

jeancaffou commented 11 years ago

I tried with b←(9 7⍴⍳63)∊17 18 19 24 26 31 32 33 40 45 46 47
now and got WS FULL, with size 999999999

ionreq commented 11 years ago

Oh, it's just a simple Game of Life app, I see...

Well, what I just realized is, that you don't even have to alter the source code. It is enough to look at the transposed array.

Hmmm, a padding of one layer of 0s should be enough, shouldnt it? Or do you need two?

jeancaffou commented 11 years ago

Yeah, a padding of one layer should be enough, however, generating the next generation of the printed solution results in the image above. It has the "9" in the middle, but no padding.

ionreq commented 11 years ago

I've tried a 6x8 padding and a 7x9 padding of the original 5x7 array, in both transpositions respectively, but couldnt get it to work. Now this is really annoying and lame, damit. I cant leave this this way. I will think of a way how to do this. In APL, with my program. I will mail you, when I've got something. Sorry, that it doesn't work so far.

jeancaffou commented 11 years ago

Woah, you're fast.

I did try the program in the link you suggested, it actually works quite nicely. 9

But I do like your version better. I mean, the code is so short I don't even understand how it's possible. But then again, this is the first time I saw APL.

Yeah, drop me an e-mail if you crack it! You're awesome.

Jean (Žan)

ionreq commented 11 years ago

Hi Jean, first of all thank you very much for your star, that's awesome! And thank you again for your feedback! It improved the program so much, I learned more APL, and who knows, if I ever would have had a look at it again without you. The new source is golreverse2.txt. Now zero cell boundary conditions are applied from the start. This makes everything so much easier. It finds now all configs for your 9er example. The 9 is padded with two layers of 0s. You have them in the c array after executing "main". In d is stored how many live cells the respective config has. So you can make a statistic now how many configs for a given number of live cells there are. This is done in the f array, and it turns out there are 4 configs with only 9 live cells! (The 9er config having 12 live cells.) These are filtered out in the following and displayed together with a test if they really become the 9. (To see all this you need to scroll up a little, but you already know that probably.) To enter other start configs you need to comment out the appropriate line first that sets b to the padded nine. But I guess you can figure that all out. If you still need help, don't hesitate to ask. Thanks again, Stephan

jeancaffou commented 11 years ago

Hey, thanks.

I've tried the new code and it's crazy fast!

There aren't many things I understand from the code, APL looks like something from an other planet. And I've seen and gotten knee deep into quite a few funny (and mainly unpratical) languages, like BF, Whitespace or Piet. Piet's kinda beautiful.

But there's one thing that really bugs me - how the heck does this make a 9er matrix? (5 3⍴⍳15)∊5 10 11 I mean, I can see that it does, but I just don't get it. And the one-liner for the actual GoL ?! Dude.

With some tinkering around the initial config I've managed to get previous generations for other numbers, letters and patterns and completed the puzzle I've started making yesterday. Hopefully it should be solvable by hand, by following the rules of GoL.

Funny thing is, I was searching for a reverse life a year ago and didn't find anything useful, other than a few snappy comments on forums that it's really hard to do, and impossible to do it any other way than bruteforce. So this find was a real treat. The fact that it's made in APL and so darn short is just crazy. I'll definitely have to show this to somebody else. Especially b←(8 9⍴⍳72)∊12 13 15 16 20 23 26 29 35 39 43 49 51 59 with g←(d=17)/c I got 20 solutions with 17 (fewest) live cells. In like two seconds. That's amazing. I'm gonna have to use this pattern for Valentine's day or something.

Thanks again!

ionreq commented 11 years ago

your puzzle program sounds interesting. i've tried your config and it seems that there are only non symmetric solutions with d=17. but there have to be symmetric ones, right? this would be an interesting little task: to write a little apl routine that finds all the symmetric solutions in there. wanna try it?

the explanation for the nine is easy: there's a tilde, bitwise negation in front of it! so i set the "holes" in the nine equal one and then bit invert.

the gol one liner is basically a convolution with a ring kernel (i.e. all pixels set in the 3x3 array except the middle one). i did it this way because i wanted to be able to use the numbers 2 and 3 for the neighbour count evaluation.

jeancaffou commented 11 years ago

Hey, well, it's not a program (it might be, someday), just a printed out grid, that a player has to solve by hand to get a pattern. I'll see how well it will be accepted among acquaintances. You could think of it as a variant of Nonogram. Solving the game of life by hand, for the fun of it. Nobody's done that before, I'd say.

Yeah! It's really weird the reverse generation of a symmetric pattern is not symmetric! Thanks for the explanation on the tilde, I didn't look it up, I just assumed it was a bitwise OR, or something, because of the "pad pad". Makes sense now, to define a pattern by reverse.