Kode yang menjalankan Game of Life dengan sendirinya

43

Menulis dua blok persegi panjang kode, setiap w lebar karakter dan h karakter tinggi, yang menerapkan permainan Conway of Life ketika diatur dalam grid. ( w dan h dapat berupa bilangan bulat positif)

Misalnya, dua blok kode mungkin: ( w = 3, h = 2, bukan kode aktual)

XX|
--+

dan

  |
--+

Perlakukan blok pertama seolah-olah itu adalah sel "hidup" di Game of Life dan blok kedua seolah-olah itu adalah sel "mati".

Sekarang atur banyak salinan dari dua blok ini ke dalam program yang lebih besar yang mewakili kisi Game of Life, seperti glider ini :

  |  |  |  |  |
--+--+--+--+--+
  |  |XX|  |  |
--+--+--+--+--+
  |  |  |XX|  |
--+--+--+--+--+
  |XX|XX|XX|  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+

Sekarang di sini adalah titik kuncinya: ketika kode ini dijalankan, outputnya haruslah grid Game of Life yang merupakan generasi setelah ini, menggunakan blok kode hidup dan mati yang sama untuk sel.

Jadi output ke program di atas akan menjadi generasi berikutnya dari glider, yang juga berfungsi sebagai program runnable:

  |  |  |  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+
  |XX|  |XX|  |
--+--+--+--+--+
  |  |XX|XX|  |
--+--+--+--+--+
  |  |XX|  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+

Menjalankan ini akan menghasilkan generasi berikutnya:

  |  |  |  |  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+
  |  |  |XX|  |
--+--+--+--+--+
  |XX|  |XX|  |
--+--+--+--+--+
  |  |XX|XX|  |
--+--+--+--+--+
  |  |  |  |  |
--+--+--+--+--+

Dan seterusnya.

Proses tersebut harus dapat diulang tanpa batas waktu dan berfungsi untuk pengaturan blok kode hidup dan mati Anda dalam kisi Game of Life.

Grid output harus memiliki dimensi yang sama dengan program asalnya (5 oleh 6 di atas). Ukuran kisi sekecil 1 per 1 seharusnya bisa digunakan, dan ukurannya mungkin semena-mena. Secara alami, sebuah grid kosong hanya akan menampilkan dirinya sendiri.

Pembaruan: Mampu mensimulasikan kisi-kisi dimensi apa pun tanpa harus mengubah "petak" akan ideal tetapi karena ini tampaknya sangat sulit saya akan menerima jawaban yang menganggap kisi-kisi adalah ukuran tertentu (mungkin sekitar 16 * 16).

Aturan Game of Life adalah sebagai berikut:

  1. Setiap sel hidup dengan kurang dari 2 atau lebih dari 3 tetangga ( Moore ) mati.
  2. Setiap sel mati dengan 3 tetangga hidup menjadi hidup.
  3. Sel-sel lain tidak berubah.

Mencetak gol

Tantangannya adalah melakukan ini di area blok kode sekecil mungkin. Skor Anda adalah w * h . Skor terendah menang. Dalam hal ikatan, jawaban dengan suara terbanyak menang.

Detail

  • Selain baris baru yang diperlukan untuk membuat hal-hal menjadi empat persegi panjang, dua blok kode Anda (dan karena itu program grid Game of Life Anda) hanya boleh berisi karakter ASCII yang dapat dicetak (kode hex 20 hingga 7E, tanpa tab, tanpa baris baru tambahan ).
  • Kedua blok kode harus memiliki karakter w * h (selain baris baru yang diperlukan) dengan setidaknya satu perbedaan karakter. Mengisi mereka dengan spasi atau komentar tidak masalah. Mereka seharusnya tidak berubah dari satu generasi ke generasi berikutnya.
  • Outputnya harus pergi ke file atau ke stdout. Tidak ada input.
  • Kondisi batas dapat berupa periodik (di mana tepi atas berbatasan dengan bawah dan tepi kiri berbatasan dengan kanan) atau tak terbatas (di mana semua sel di luar batas selalu mati). Pilih yang cocok untuk Anda.
  • Membaca kode sumber Anda sendiri tidak diperbolehkan.
  • Bahasa atau alat apa pun yang sudah melakukan ini tidak diizinkan. (Kalau-kalau ada satu.)

Catatan: The -|+karakter di atas hanya digunakan untuk menekankan batas sel. Blok Anda tidak memerlukan batas yang dapat dibedakan. Namun , ketika menampilkan output Anda akan sangat membantu jika ada beberapa pemisahan yang dapat dibedakan antara blok, mungkin dibuat dengan karakter yang tidak pernah digunakan dalam program sehingga mudah untuk dihapus. misalnya

DD+DD+DD+DD
+++++++++++
AA+DD+AA+DD

dari pada

DDDDDDDD
AADDAADD
Hobi Calvin
sumber
1
ini sepertinya tantangan yang cocok untuk dihancurkan atau> <>. di mana pria yang selalu memiliki jawaban di> <>?
haskeller bangga
1
@ MartinBüttner Saya akan mengatakan itu baik-baik saja, asalkan tidak seperti itu __SOURCE_CODE__.
Calvin Hobbies
2
@proudhaskeller Saya pikir itu saya dan saya sudah mengerjakan satu di> <> :) - ini KERAS.
tommeding
2
Apakah ukuran arena diperbolehkan untuk dikodekan atau haruskah program menyelesaikannya sendiri? Artinya, apakah kode perlu bekerja di arena ukuran yang sewenang-wenang?
trichoplax
1
@githubphagocy Idealnya ini akan bekerja di arena yang sewenang-wenang, tetapi saya dapat melonggarkan kendala itu karena sangat sulit untuk diterapkan.
Hobi Calvin

Jawaban:

12

Perl, w * h = 233 * 1 = 233 (per sel)

Sel bekerja dalam ukuran kisi apa saja (sebenarnya bahkan dengan panjang baris tidak beraturan). Di luar batas sel dianggap mati.

Sel Mati

my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});

Sel hidup

my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});

Pesawat peluncur

my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});

menghasilkan:

my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=1}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});
my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});my$y;INIT{$y=__LINE__;$h{++$x{$y}}{$y}=0}eval($c=q{$n=0;$o++;for$i(-1..1){$n+=$i|$_&&$h{$o+$i}{$y+$_}for(-1..1)}print"my\$y;INIT{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=",$n==2?$h{$o}{$y}:$n==3||0,"}eval(\$c=q{$c});",!($o%=$x{$y})&&"\n"});

Penjelasan (tidak terkini)

# Perl has several special blocks that are executed at certain stages.
# BEGIN blocks are executed at compilation stage
BEGIN
{
  # current row index and row count in execution stage
  $y=__LINE__;
  # $x{$y} is the cell index in current row and cell count in execution stage
  # $h{..}{..} set cell to dead || alive
  $h{++$x{$y}}{$y}=1
}

# dead || alive
$v=1;
# row index
$p=__LINE__;
# write cell code to $c
$c=q{
  # reset neighbour count
  $n=0;
  # cell index
  $o++;
  # count living neighbours
  for$i(-1..1){$n+=$i|$_?$h{$o+$i}{$p+$_}:0for(-1..1)}
  # reset cell index to 0 when end of row is reached
  $o%=$x{$p};
  # dead || alive for next generation of this cell
  $v=$n==3||$n==2&&$v||0;
  # print the new cell
  print"BEGIN{\$y=__LINE__;\$h{++\$x{\$y}}{\$y}=$v}\$v=$v;\$p=__LINE__;\$c=q{$c};eval\$c;",$o?"":"\n"
};
# execute cell code
eval$c;

Perl, w * h = 140 * 2 = 280 (per sel)

Sel multi-line tidak efisien tetapi dapat dihilangkan __LINE__.

Sel Mati

BEGIN{++$v}eval($c=q<;;;;;;++$y;map{$i{$y}+=$h{$y+$_}}(-$a-1..-$a+1,-1,1,$a-1..$a+1);print'BEGIN{++$v}eval($c=q<',$c,'>);',!($y%$a)&&"\n">);
BEGIN{$a||=$v,$h{++$x}=0}eval($c=q<$n=$i{++$z};print'BEGIN{$a||=$v,$h{++$x}=',$n==2?$h{$z}:$n==3||0,'}eval($c=q<',$c,'>);',!($z-$y)&&"\n">);

Sel hidup

BEGIN{++$v}eval($c=q<;;;;;;++$y;map{$i{$y}+=$h{$y+$_}}(-$a-1..-$a+1,-1,1,$a-1..$a+1);print'BEGIN{++$v}eval($c=q<',$c,'>);',!($y%$a)&&"\n">);
BEGIN{$a||=$v,$h{++$x}=1}eval($c=q<$n=$i{++$z};print'BEGIN{$a||=$v,$h{++$x}=',$n==2?$h{$z}:$n==3||0,'}eval($c=q<',$c,'>);',!($z-$y)&&"\n">);
Thaylon
sumber
8

JavaScript ES6 (239 x 1 karakter per sel)

Sel mati:

f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');

Sel hidup:

f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');

Hanya perbedaan untuk sel S[j]=0mati dan S[j]=1sel hidup.

Ukuran kisi dikendalikan dengan variabel W (lebar) dan H (tinggi). Sel di luar kotak mati.

Versi yang dikomentari

f=r=>{
    S=S||[],    // cell states
    j=S.length, // current index
    S[j]=1,     // state of this cell
    W=5,        // width of grid
    H=6;        // height of grid
    if (j+2 > W*H)  // if last cell
        /* Loop all cells and gather code for output */
        for (i in S)
            /* Function source with state replaced */
            r +=("f="+f+";f('');").replace(/0|1/, ~~[S[i],1] // lookup table
                [~~S[i-W] + ~~S[+i+W] + // +i to convert from int to string
                ~~(i % W ? S[--i] + S[i-W] + S[W+i++] : 0) +
                ~~(i % W < W-1 ? S[++i] + S[i-W] + S[W+i--] : 0)-2]),
            r = ++i % W ? r : (console.log(r), "")
};
f(''); // call current cell function to set state of the cell

Glider (grid 5 x 6)

f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');

Keluaran generasi berikutnya:

f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=1,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');f=e=>{S=S||[],j=S.length,S[j]=0,W=5,H=6;if(j+2>W*H)for(i in S)e+=("f="+f+";f('');").replace(/0|1/,~~[S[i],1][~~S[i-W]+~~S[+i+W]+~~(i%W?S[--i]+S[i-W]+S[W+i++]:0)+~~(i%W<W-1?S[++i]+S[i-W]+S[W+i--]:0)-2]),e=++i%W?e:(console.log(e),"")};f('');
Mika Lammi
sumber
'S == 0 &&' in '(v <2 || v> 3? 0: s == 0 && v == 3? 1: s)' tampaknya berlebihan.
Thaylon
@Thaylon Terima kasih atas komentarnya, saya akan memeriksanya. Saat ini saya sedang melakukan beberapa perbaikan. Sepertinya versi berikutnya akan menjadi ~ 300 karakter.
Mika Lammi
@ mbomb007 No. |adalah operator bitwise dan hanya bekerja dengan angka. ||adalah operator logis yang mengembalikan sisi kiri jika "benar", sisi kanan sebaliknya.
Mika Lammi
5

Python, 67x33 = 2.211

Perhatikan, bahwa ini adalah versi cantik saya, di mana saya menambahkan baris "#" ke setiap baris lain di sel kehidupan, dan "" ke setiap baris lain di sel mati. Selain itu, sel-sel dipisahkan oleh garis "#". Dengan cara ini, Anda dapat menempatkan konfigurasi awal dalam file teks, misalnya GOL.py, dan melihatnya dengan font kecil untuk melihat apa yang terjadi pada setiap langkah. Untuk sampai ke langkah berikutnya, jalankan python GOL.py > GOL1.py;mv GOL1.py GOL.pydan lihat lagi.

Solusi saya bekerja pada kisi ukuran sewenang-wenang dan mengasumsikan kondisi batas periodik. Saya belum menguji berbagai garis lebar, tetapi pasti ada kemampuan untuk itu.

Saya juga harus menyebutkan, bahwa keberhasilan solusi ini tergantung pada __del__dipanggil ketika adihancurkan pada akhir program. The Python dokumentasi negara

Tidak dijamin bahwa __del__()metode dipanggil untuk objek yang masih ada saat juru bahasa keluar.

Jadi, saya hanya berharap, ini tidak hanya bekerja dengan penerjemah saya.

Sel hidup:

c=['import sys;o=sys.stdout.write;r=range;l=len;w=66',#############
###################################################################
'class B(list):',' def __getitem__(s,k):',#########################
###################################################################
'  return list.__getitem__(s,k%l(s))','class A(B):',###############
###################################################################
' def e(s,k,m):','  g=(s[k-1][m]+s[k+1][m]+s[k][m-1]+s[k][m+1]',###
###################################################################
'+s[k-1][m-1]+s[k-1][m+1]+s[k+1][m-1]+s[k+1][m+1])',###############
###################################################################
'  if s[k][m]==0:return 1 if g==3 else 0',#########################
###################################################################
'  return 1 if g==2 or g==3 else 0',' def u(s,i,y,b):',############
###################################################################
'  for j in r(l(s[i])):o(y+b[s.e(i,j)]*(w-l(y))+"#")',#############
###################################################################
'  print;print"#".join([b[s.e(i,j)]*w for j in r(l(s[i]))])+"#"',##
###################################################################
' def __del__(s):','  for i in r(l(s)):','   y="";b=[" ","#"]',####
###################################################################
'   for q in ["c=["]+[repr(x)+","for x in c]+[',###################
###################################################################
'"];import os;exec(os.linesep.join(c))"]:',########################
###################################################################
'    if l(y+q)>w:s.u(i,y,b);y=""','    y+=q','   s.u(i,y,b)',######
###################################################################
'   for j in r(l(s[i])):o("a[-1].append(%i);"%s.e(i,j)+" "*51)',###
###################################################################
'   print;print "#"*l(s[i])*(w+1)','if "a" not in locals():a=A()',#
###################################################################
'a.append(B())',];import os;exec(os.linesep.join(c))###############
###################################################################
a[-1].append(1);                                                   
###################################################################

Sel mati:

c=['import sys;o=sys.stdout.write;r=range;l=len;w=66',            #
                                                                  #
'class B(list):',' def __getitem__(s,k):',                        #
                                                                  #
'  return list.__getitem__(s,k%l(s))','class A(B):',              #
                                                                  #
' def e(s,k,m):','  g=(s[k-1][m]+s[k+1][m]+s[k][m-1]+s[k][m+1]',  #
                                                                  #
'+s[k-1][m-1]+s[k-1][m+1]+s[k+1][m-1]+s[k+1][m+1])',              #
                                                                  #
'  if s[k][m]==0:return 1 if g==3 else 0',                        #
                                                                  #
'  return 1 if g==2 or g==3 else 0',' def u(s,i,y,b):',           #
                                                                  #
'  for j in r(l(s[i])):o(y+b[s.e(i,j)]*(w-l(y))+"#")',            #
                                                                  #
'  print;print"#".join([b[s.e(i,j)]*w for j in r(l(s[i]))])+"#"', #
                                                                  #
' def __del__(s):','  for i in r(l(s)):','   y="";b=[" ","#"]',   #
                                                                  #
'   for q in ["c=["]+[repr(x)+","for x in c]+[',                  #
                                                                  #
'"];import os;exec(os.linesep.join(c))"]:',                       #
                                                                  #
'    if l(y+q)>w:s.u(i,y,b);y=""','    y+=q','   s.u(i,y,b)',     #
                                                                  #
'   for j in r(l(s[i])):o("a[-1].append(%i);"%s.e(i,j)+" "*51)',  #
                                                                  #
'   print;print "#"*l(s[i])*(w+1)','if "a" not in locals():a=A()',#
                                                                  #
'a.append(B())',];import os;exec(os.linesep.join(c))              #
                                                                  #
a[-1].append(0);                                                   
###################################################################

Python, 67x17 = 1.139 Untuk mendapatkan versi golf , masih dengan beberapa cara untuk mengenali sel-sel kehidupan dari jauh, pernyataan cetak kedua di baris 19 dan 31 serta setiap baris lainnya dihapus.

Sel hidup:

c=['import sys;o=sys.stdout.write;r=range;l=len;w=66',#############
'class B(list):',' def __getitem__(s,k):',#########################
'  return list.__getitem__(s,k%l(s))','class A(B):',###############
' def e(s,k,m):','  g=(s[k-1][m]+s[k+1][m]+s[k][m-1]+s[k][m+1]',###
'+s[k-1][m-1]+s[k-1][m+1]+s[k+1][m-1]+s[k+1][m+1])',###############
'  if s[k][m]==0: return 1 if g==3 else 0',########################
'  return 1 if g==2 or g==3 else 0',' def u(s,i,y,b):',############
'  for j in r(l(s[i])):o(y+b[s.e(i,j)]*(w-l(y))+"#")','  print',###
' def __del__(s):','  for i in r(l(s)):','   y="";b=[" ","#"]',####
'   for q in ["c=["]+[repr(x)+","for x in c]+[',###################
'"];import os;exec(os.linesep.join(c))"]:',########################
'    if l(y+q)>w:s.u(i,y,b);y=""','    y+=q','   s.u(i,y,b)',######
'   for j in r(l(s[i])):o("a[-1].append(%i);"%s.e(i,j)+" "*51)',###
'   print','if "a" not in locals():a=A()','a.append(B())',#########
];import os;exec(os.linesep.join(c))###############################
a[-1].append(1);                                                   

Sel mati:

c=['import sys;o=sys.stdout.write;r=range;l=len;w=66',            #
'class B(list):',' def __getitem__(s,k):',                        #
'  return list.__getitem__(s,k%l(s))','class A(B):',              #
' def e(s,k,m):','  g=(s[k-1][m]+s[k+1][m]+s[k][m-1]+s[k][m+1]',  #
'+s[k-1][m-1]+s[k-1][m+1]+s[k+1][m-1]+s[k+1][m+1])',              #
'  if s[k][m]==0: return 1 if g==3 else 0',                       #
'  return 1 if g==2 or g==3 else 0',' def u(s,i,y,b):',           #
'  for j in r(l(s[i])):o(y+b[s.e(i,j)]*(w-l(y))+"#")','  print',  #
' def __del__(s):','  for i in r(l(s)):','   y="";b=[" ","#"]',   #
'   for q in ["c=["]+[repr(x)+","for x in c]+[',                  #
'"];import os;exec(os.linesep.join(c))"]:',                       #
'    if l(y+q)>w:s.u(i,y,b);y=""','    y+=q','   s.u(i,y,b)',     #
'   for j in r(l(s[i])):o("a[-1].append(%i);"%s.e(i,j)+" "*51)',  #
'   print','if "a" not in locals():a=A()','a.append(B())',        #
];import os;exec(os.linesep.join(c))                              #
a[-1].append(0);                                                   

Jika ada permintaan, saya dengan senang hati akan menjelaskan cara kerja solusi saya ketika saya menemukan waktu.

M.Herzkamp
sumber
Saya mencoba menggunakan <sup><sub>...</sub></sup>dalam satu <pre><code>blok. Ini tidak mengurangi ketinggian garis, tetapi font teks berkurang untuk setiap kemunculannya. Hanya menggunakan subskrip atau hanya superskrip akan membuat kode melayang turun atau naik di luar markup, tetapi bergantian akan membuatnya tetap terpusat secara vertikal.
mbomb007
@ mbomb007 Sepertinya Anda menemukan jalan setelah semua ;-)
M.Herzkamp
Ya, saya pikir itu membantu program yang lebih kecil terlihat seperti kotak, setidaknya.
mbomb007
Saya pikir akan lebih baik jika versi golf berada di atas jawaban, dengan nilainya tercantum di header. Juga, saya pikir Anda bisa bermain golf lebih banyak.
mbomb007
Saya memasukkannya ke dalam urutan ini karena saya pikir versi yang tidak serigala lebih semangat pertanyaan (nilainya biasa-biasa saja di terbaik). Btw. @ mbomb007 Saya mulai curiga bahwa Anda memberikan lebih banyak waktu ke jawaban ini daripada saya: P Apakah ada cara untuk membagikan skor?
M.Herzkamp