previndexinfonext

code guessing, round #65 (completed)

started at ; stage 2 at ; ended at

specification

evaporate or proliferate, the choice is yours. but! your challenge is to find out if a cellular automaton conserves population. submissions can be written in any language.

right, here we go. for simplicity, we'll be dealing with 2D automata with 3x3 neighbourhoods and 2 states. that means cells see themselves and everything in their Moore neighbourhood, for instance:

0 1 1
1 0 1
1 1 0

and from that, they decide which state they should have in the next generation: 0 or 1. as there are 29 = 512 possible combinations of 9 cells, this means there are 2512 possible automata and that each one can be represented by a 512-bit number. for instance, conway's game of life is 100010001000101170116000100010117011601170116177E1668000100010117011601170116177E166801170116177E1668177E16687EE8688016.

a number-conserving automaton is one in which each generation is guaranteed to preserve the "population", or number of cells which are 1, of the configuration. a trivial example is FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF0000000016, in which every live cell "moves right" forever. conway's game of life, on the other hand, is not number-preserving, as the population can decrease (such as when a lone cell dies) or increase (such as from a glider gun). the population must be constant on every step for the automaton to be number-preserving.

your challenge, given a representation of a two-dimensional 2-state cellular automaton using Moore neighbourhood, is to decide whether the automaton is number-conserving. as any language is allowed, there is no fixed API.

results

  1. 👑 essaie +2 -2 = 0
    1. LyricLy
    2. olus2000
  2. LyricLy +2 -2 = 0
    1. olus2000
    2. essaie
  3. olus2000 +2 -2 = 0
    1. LyricLy
    2. essaie

entries

you can download all the entries

entry #1

written by LyricLy
submitted at
0 likes

guesses
comments 0

post a comment


reprehensiblensible.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import numpy as np

def sum_tests(f, arr, chop_x, chop_y):
    piece = arr[chop_x:, chop_y:]
    s = 0
    for cx, i in enumerate(range(chop_x, 3)):
        for cy, j in enumerate(range(chop_y, 3)):
            if not (i or j):
                continue
            t = np.pad(piece[:-cx or None, :-cy or None], ((i, 0), (j, 0)))
            s += f(t)
    return s

def f(arr):
    if arr[1, 1]:
        return arr[1, 2]
    else:
        return arr[1, 0]

def is_nc(f):
    for n in range(512):
        arr = (n & 1 << np.arange(9).reshape((3, 3))).astype(bool)
        if (f(arr) !=
            arr[0, 0]
            + sum_tests(f, arr, True, False)
            + sum_tests(f, arr, False, True)
            - sum_tests(f, arr, False, False)
            - sum_tests(f, arr, True, True)
           ):
            return False
    return True

def fofn(n):
    def f(arr):
        return (n >> int(np.sum(arr * (1 << np.arange(9).reshape((3, 3)))))) & 1
    return f

def entry(n):
    return is_nc(fofn(n))

entry #2

written by olus2000
submitted at
0 likes

guesses
comments 0

post a comment


entry_17.py Unicode text, UTF-8 text, with CRLF line terminators
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
up = [None]
char = [None]
def output(n):
	if n == 0: return ''
	return output(up[n]) + char[n]
n = 0
s = iter('''
\0"\2"\1D\0A\0R\0K\0 \0D\5R\7E\6 \0Y\0E\0T\10D
K\16R\1T\0H\16 	A\6K\0N\16S\0S\10K\16E\0P\32 \0G\6O\0W\0I\30G\23H\25S\24A	O!S\10C\0U\17T"N\37 	E\16P\22
\35H\0O\17O\30 \6E\5D,G\34N\14G\5T"V\14
\17H"S\10N\16X\17 @P\22I\0M\16N\17
\32E\16M\32
\0V\22Y\1VK
,T\22E\32T7
\0.R.\1W&T\20O\10Y2U\10T!OYH,K\1"\3
\0d\0e\0f\10I\30TOS\17I#(=I\32,?E\0X\17,\10EjPCMET\0)\0:\1	BE\6IDE\10=\x080rf\0o\0rlX\35EtME \0i\0n\10r\0a\x80g`(gS\10-\x081\0,[I\36+\x082p:r	\x7ffw \0<\0={PnE4<\x870\x000q
\0	\x98	aoz sR"M\10i\x80 za\x83e\0(\30EjT\x86 \x001\x88 £XA+\x8b)\x97	\x99	\x9cIu \0*\x91 \x002\x8d	\x98ia \x96 \x90=\x92E} \x90 ¦0\x96\x98EmE}E\10+°E¾R\x9dEc[\xadME]\0[Å]\x8de\x00l\0s`:²EÂI®*°8rr`t\0uzn·RÃ
arym\x81a\x80\x7fm\0pyr\0tÙn_r\x82n\0g`
Ýr\x7fnß(\2WU ' \rO* \17W2 gN\7?\2)\4A\27 °i\x80t¢i\x80pÓt¢)§1\x006p
\x9ar\20A\27N\31S\x9enàg\x841\x960\x96)«pzi\x9f=\10[\x8d[µfÞ åiā \xa0nãe¢1Ą)\0]\x8di´râ æ ¢0§9\x009p `lËeĊ0\x9ef\10pć ė(\x96,\x089Ě)\10eÊs` ďdďg\x842ěfČpġi\x9frâgă0ą]\x8dfČrĖiįa¡(º0ü	ē
\x98rİ °sÓm¢m\x82p¢sľ,Ġræ)ĹD\21E\14
\x99[²(\26R\7 \0>ō NE5SeN\37(č,à,Ńi\x80)ě&\x87
¬fĭr\x7f ėrİeđ0ą
\x99]ijo\x9brĵnĂeŞ0Ĺ]rEÎM\25=\10sľ(\0mŀ(ËuŬ,þR\13Rp)riĕa\x83 ŎEŨE«	čnç"1O3N\10R\16A\tI# \35O\32IeV\16"Ĺ	`x\x7ftđ7ĹiŴnã ¹Eŷ:\x8dpćnźT\24EŰK£S\36K\34P\x36G W7"ƅe\0xƇ(¦7üpƏt¢"GEDSS.ñ
ŹtƟVK"ƝrætƥE\6Yƣpƞ(\2IcEŐTƘ)\1pƬ"Ƣ"ü''')
res = ''
try:
	while True:
		c = next(s)
		up.append(n)
		char.append(c)
		n = ord(next(s))
		res += c + output(n)
except StopIteration:
	pass
exec(res)

entry #3

written by essaie
submitted at
0 likes

guesses
comments 0

post a comment


free_guess.py ASCII text, with CR line terminators
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def jam(semikibibit):
  tot = 0
  while semikibibit:
    tot += semikibibit % 2
    semikibibit //= 2
  far = abs(256 - tot)
  if far == 256:
    return "no"
  elif far == 0:
    return "probably"
  elif far > 100:
    return "probably not"
  else:
    return "hard to tell"