def AND3(a,b,c): return a and (b and c) def OR4(a,b,c,d): return (a or b) or (c or d) def UNIV2(A, B, d00, d01, d10, d11): w = AND3(not A, not B, d00) x = AND3(not A, B, d01) y = AND3(A, not B, d10) z = AND3(A, B, d11) return OR4(w,x,y,z) def ifthenelse5(bit, byte1, byte2): return [(byte1[0] and bit) or (byte2[0] and not bit), (byte1[1] and bit) or (byte2[1] and not bit), (byte1[2] and bit) or (byte2[2] and not bit), (byte1[3] and bit) or (byte2[3] and not bit), (byte1[4] and bit) or (byte2[4] and not bit)] def ascii(c): seq = ['_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] i = sum([n*(seq[n]==c) for n in range(len(seq))]) return [i/16 == 1, (i/8)%2 == 1, (i/4)%2 == 1, (i/2)%2 == 1, i%2 == 1] def inputbits(str): return [ascii(str[i]) for i in range(len(str))] # word is 7 groups of 5 bits each def exception(word): ps = exception3(ascii('_'), word[0], word[1]) p0 = exception3(word[0], word[1], word[2]) p1 = exception3(word[1], word[2], word[3]) p2 = exception3(word[2], word[3], word[4]) p3 = exception3(word[3], word[4], word[5]) p4 = exception3(word[4], word[5], word[6]) return ((ps or p0) or p1) or (p2 or (p3 or p4)) # match two bits def equal(bit1, bit2): return ((bit1 and bit2) or (not bit1 and not bit2)) # 5 matching bits def equal5(char1, char2): return (equal(char1[0],char2[0]) and (equal(char1[1],char2[1]) and (equal(char1[2],char2[2]) and (equal(char1[3],char2[3]) and equal(char1[4],char2[4]))))) # 3 consecutive letters def exception3(x,y,z): ex1 = AND3(equal5(x,ascii('c')),equal5(y,ascii('i')),equal5(z,ascii('e'))) ex2 = AND3(not equal5(x,ascii('c')),equal5(y,ascii('e')),equal5(z,ascii('i'))) return ex1 or ex2 exception(inputbits('glacier'))