def gen_sq(sq): global counter root = Node(None, sq) unvisited.enqueue(root) exist[cantor.cantor(root.sq) - 1] = 1 while(not unvisited.is_empty()): current = unvisited.head() current.childs = [Node(current, x) for x in gen_childs(current.sq) if not exist[cantor.cantor(x) - 1]] for x in current.childs: exist[cantor.cantor(x.sq) - 1] = 1 counter += 1 map(lambda x : unvisited.enqueue(x), current.childs) unvisited.dequeue()
def search(sq): root = Node(None, sq) unvisited_search.enqueue(root) exist_search[cantor.cantor(root.sq) - 1] = 1 while(not unvisited_search.is_empty()): current = unvisited_search.head() current.childs = [Node(current, x) for x in gen_childs(current.sq) if not exist_search[cantor.cantor(x) - 1]] if test_square(current.sq): print_trace(current) break for x in current.childs: exist_search[cantor.cantor(x.sq) - 1] = 1 map(lambda x : unvisited_search.enqueue(x), current.childs) unvisited_search.dequeue()
def decrease(t, n): if(t == 0 or t > length(n)): return -1 k=list() for _ in range(t-1): s, n = c.reverse(n) k.append(s) s, n = c.reverse(n) k.append(s-1) k.reverse() for i in k: n = c.cantor(i,n) return n
import cantor import integerList as il #cantor(x,y) assert (cantor.cantor(0, 0) == 1) assert (cantor.cantor(0, 3) == 10) assert (cantor.cantor(4, 0) == 11) assert (cantor.cantor(3, 2) == 18) print("Ok cantor") #gamma(n) assert (cantor.gamma(486) == 30) assert (cantor.gamma(12) == 4) assert (cantor.gamma(1) == 0) assert (cantor.gamma(9) == 3) print("Ok gamma") #sx(n) assert (cantor.sx(9) == 1) assert (cantor.sx(13) == 2) assert (cantor.sx(18) == 3) assert (cantor.sx(1) == 0) print("Ok sx") #dx(n) assert (cantor.dx(12) == 1) assert (cantor.dx(19) == 3) assert (cantor.dx(22) == 0) assert (cantor.dx(1) == 0) print("Ok dx")
def encode(l): k=0 l.reverse() for i in l: k = c.cantor(i, k) return k