Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/maze-generation/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / maze-generation / oracle.py` 39 lines ยท 1504 bytes Raw Blame History 1 # Independent reference for "Maze generation" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 M = 2 ** 64 4 x = 0 5 def rnd(): 6 global x 7 x = (x * `6364136223846793005` + `1442695040888963407`) % M 8 return x >> 33 9 W, H = 10, 6 10 def generate(): 11 east = [[True] * W for _ in range(H)] 12 south = [[True] * W for _ in range(H)] 13 seen = {(0, 0)} 14 stack = [(0, 0)] 15 while stack: 16 r, k = stack[-1] 17 cands = [(r + dr, k + dk) for dr, dk in ((-1, 0), (0, 1), (1, 0), (0, -1)) 18 if 0 <= r + dr < H and 0 <= k + dk < W and (r + dr, k + dk) not in seen] 19 if not cands: 20 stack.pop() 21 continue 22 nr, nk = cands[rnd() % len(cands)] 23 if nr == r: 24 east[r][min(k, nk)] = False 25 else: 26 south[min(r, nr)][k] = False 27 seen.add((nr, nk)) 28 stack.append((nr, nk)) 29 return east, south 30 def draw(east, south, marked=()): 31 print("+" + "---+" * W) 32 for r in range(H): 33 print("|" + "".join((" * " if (r, k) in marked else " ") + ("|" if east[r][k] else " ") for k in range(W))) 34 print("+" + "".join("---+" if south[r][k] else " +" for k in range(W))) 35 east, south = generate() 36 # a perfect maze: 60 cells joined by exactly 59 openings, all reachable from the top-left cell 37 openings = sum(not e for row in east for e in row[:W - 1]) + sum(not s for row in south[:H - 1] for s in row) 38 assert openings == W * H - 1 39 draw(east, south)