Created
August 4, 2018 19:30
-
-
Save mcclure/c54fc6103e76279c298c7b3b63f0ffd9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
HOWMANYBITS = 5 | |
REDUCE = True | |
queue = [["A", [True]]] | |
possibilities = [[True], [False]] | |
A = ord("A") | |
print "A" | |
print "_" | |
print "A" | |
def foundstr(founditem): | |
result = "" | |
for i in range(len(founditem)): | |
v = founditem[i] | |
if v is not None: | |
if result: | |
result += " " | |
if not v: | |
result += "~" | |
result += chr(A + i) | |
return result | |
def allpossible(p): | |
found = [tuple([])] | |
for bit in p: | |
newfound = [] | |
for founditem in found: | |
if bit is None: | |
newfound.append(founditem + (True,)) | |
newfound.append(founditem + (False,)) | |
else: | |
newfound.append(founditem + (bit,)) | |
found = newfound | |
return found | |
for _ in range(HOWMANYBITS): | |
newqueue = [] | |
newpossibilities = [] | |
for p in possibilities: | |
newpossibilities.append(p + [True]) | |
newpossibilities.append(p + [False]) | |
possibilities = newpossibilities | |
for item in queue: | |
human, bitmap = item | |
bitmaplen = len(bitmap) | |
for newbit in (True, False): | |
newhuman = human + " " + ("+" if newbit else "-") + chr(A + bitmaplen) | |
newbitmap = bitmap + [newbit] | |
print newhuman | |
print ("_" * len(newhuman)) | |
foundhash = {} | |
for p in possibilities: | |
live = True | |
for i in range(len(newbitmap)): | |
if live == newbitmap[i]: | |
live = p[i] | |
if live: | |
foundhash[tuple(p)] = True | |
if REDUCE: | |
orig_foundhash = foundhash | |
#for _2 in range(bitmaplen): | |
newfoundhash = {} | |
for p in foundhash.keys(): | |
fixed = list(p) | |
for i in range(len(p)): | |
if fixed[i] is not None: | |
temp = list(fixed) | |
temp[i] = None | |
okay = True | |
tests = allpossible(temp) | |
for test in tests: | |
if test not in orig_foundhash: | |
okay = False | |
if okay: | |
fixed = temp | |
newfoundhash[tuple(fixed)] = True | |
foundhash = newfoundhash | |
for p in reversed(sorted(foundhash.keys())): | |
print(foundstr(p)) | |
newitem = [newhuman, newbitmap] | |
newqueue.append(newitem) | |
queue = newqueue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment