# Constructs a 22 x 22 random soup with diagonal symmetry based on a
# SHA-256 cryptographic hash.
def hashsoupdiag(instring):
s = hashlib.sha256(instring).digest()
thesoup = []
idx = 0
for j in xrange(22):
for k in xrange(j+1):
q, r = divmod(idx, 8)
if not r:
t = ord(s[q])
if (t & (1 << (7 - r))):
thesoup.append(k)
thesoup.append(j)
if not (j == k):
thesoup.append(j)
thesoup.append(k)
idx += 1
return thesoup
# Generate the soup from the SHA-256 of the concatenation of the
# seed with the index:
- hashsoup(root + str(pos + i))
+ thesoup = hashsoupdiag(root + str(pos + i))
+ g.putcells(thesoup, -11, -11)
...
results += "@ROOT "+root+"\n"
results += "@RULE "+self.rg.alphanumeric+"\n"
+ results += "@SOUP hashsoupdiag"
results += "@NUM_SOUPS "+str(numsoups)+"\n"
results += "@NUM_OBJECTS "+str(totobjs)+"\n"
...
# SHA-256 soups are 16-by-16:
- rledata = "x = 16, y = 16, rule = " + self.rg.slashed + "\n"
- hashdigest = souphash.digest()
- for j in xrange(32):
- t = ord(hashdigest[j])
- for k in xrange(8):
- if (t & (1 << (7 - k))):
- rledata += "o"
- else:
- rledata += "b"
- if ((j % 2) == 1):
- rledata += "$\n"
- rledata += "!\n"
+ thesoup = hashsoupdiag(root + str(soupnum))
try:
- f = open(rlepath, 'w')
- f.write(rledata)
- f.close()
+ g.store(thesoup, rlepath)
except:
g.warn("Unable to create soup pattern:\n" + rlepath)
...
results = "<html>\n<title>Census results</title>\n<body bgcolor=\"#FFFFCE\">\n"
+ results += "<p>Soup search conducted in " + self.rg.slashed + " with hashsoupdiag() soup generation.\n"
results += "<p>Census results after processing " + str(numsoups) + " soups (seed = " + root + "):\n"
I happen to know Python. Without any knowledge of your script I concocted my own (this one leaves the central diag empty as it's 23 * 23):wildmyron wrote:Here's a version of hashsoup() which creates soups with diagonal symmetry…
# \ symmetries in a 23 * 23 grid
def hashsoupdg(instring):
s = hashlib.sha256(instring).digest()
N = ord(s[0])
for k in xrange(31):
N = (N << 8) + ord(s[k + 1])
thesoup = []
for j in xrange(22):
for k in xrange(j + 1):
if N & (1 << (j * (j + 1) >> 1) + k):
thesoup.extend([j + 1, k, k, j + 1])
g.putcells(thesoup, -11, -11)
Users browsing this forum: No registered users and 1 guest