Last active
July 18, 2018 13:27
-
-
Save AlephAlpha/e129987cfe358a4b9ca1e2a51ce0812e to your computer and use it in GitHub Desktop.
Game of Life still life searcher in Mathematica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SearchStillLife[w_, h_] := | |
Block[{r = RandomInteger[1, {w, h}]}, | |
ArrayPlot[ | |
Echo[Mod[r + ArrayReshape[Boole@#, {w, h}], 2], "RLE: ", | |
"x = " <> #2 <> ", y = " <> #1 <> ", rule = B3/S23\n" & @@ | |
ToString /@ Dimensions@# <> | |
StringRiffle[ | |
StringCases[ | |
StringReplace[ | |
StringReplace[ | |
Riffle[# /. {1 -> "o", 0 -> "b"}, "$"] <> "!", | |
"b" .. ~~ s : "$" | "!" :> s], | |
r : (x_) .. /; StringLength@r > 1 :> | |
ToString@StringLength@r <> x], | |
l : (___ ~~ "o" | "b" | "$" | "!") /; StringLength@l <= 70], | |
"\n"] &], Mesh -> All] &@ | |
SatisfiabilityInstances[ | |
Array[BooleanConvert[(! b[##] && ! | |
BooleanCountingFunction[{{3}}, | |
Flatten@Array[b, {3, 3}, {##} - 1]~Delete~ | |
5]) || (b[##] && | |
BooleanCountingFunction[{{2, 3}}, | |
Flatten@Array[b, {3, 3}, {##} - 1]~Delete~5]) /. {b[i_, | |
j_] /; i < 1 || i > w || j < 1 || j > h :> False, | |
b[i_, j_] /; r[[i, j]] == 1 :> ! b[i, j]}, "CNF"] &, {w, | |
h} + 2, 0, And], Flatten@Array[b, {w, h}]][[1]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment