#!/usr/bin/env python3 import logging from argparse import ArgumentParser logger = logging.getLogger(__name__) def parse_args(): ap = ArgumentParser() ap.add_argument("-v", "--verbose", action="store_true") return ap.parse_args() def read_ints(): return [int(x) for x in input().split()] # def inside(x: int, y: int, n: int) -> bool: # return (0 <= x < n) and (0 <= y < n) def is_blocked(t: list[list[int | None]], x: int, y: int) -> bool: try: return t[x][y] is not None except IndexError: return True def dump(t) -> None: for row in t: for c in row: print(c, end="") print() print() def main(): args = parse_args() logging.basicConfig(level=logging.INFO if args.verbose else logging.WARNING) n = 100 t = [[None for _ in range(n)] for _ in range(n)] # print(t) x = 0 y = 0 dx = 1 dy = 0 current = 0 # dog = 0 missing = n * n while True: # if t[x][y] is not None: # break if t[x][y] is None: missing -= 1 t[x][y] = current # print(f"{x=} {y=} => {current} {missing=}") next_x = x + dx next_y = y + dy # if not inside(x=next_x,y= next_x , n=n) or t[next_x][next_y]: if is_blocked(t=t, x=next_x, y=next_y): dx, dy = -dy, dx current = 1 - current next_x = x next_y = y x = next_x y = next_y if missing == 0: t[x][y] = 1 - t[x][y] break # dog += 1 # if dog > 50: # break dump(t) if __name__ == "__main__": main()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #!/usr/bin/env python3 import logging from argparse import ArgumentParser logger = logging.getLogger(__name__) def parse_args(): ap = ArgumentParser() ap.add_argument("-v", "--verbose", action="store_true") return ap.parse_args() def read_ints(): return [int(x) for x in input().split()] # def inside(x: int, y: int, n: int) -> bool: # return (0 <= x < n) and (0 <= y < n) def is_blocked(t: list[list[int | None]], x: int, y: int) -> bool: try: return t[x][y] is not None except IndexError: return True def dump(t) -> None: for row in t: for c in row: print(c, end="") print() print() def main(): args = parse_args() logging.basicConfig(level=logging.INFO if args.verbose else logging.WARNING) n = 100 t = [[None for _ in range(n)] for _ in range(n)] # print(t) x = 0 y = 0 dx = 1 dy = 0 current = 0 # dog = 0 missing = n * n while True: # if t[x][y] is not None: # break if t[x][y] is None: missing -= 1 t[x][y] = current # print(f"{x=} {y=} => {current} {missing=}") next_x = x + dx next_y = y + dy # if not inside(x=next_x,y= next_x , n=n) or t[next_x][next_y]: if is_blocked(t=t, x=next_x, y=next_y): dx, dy = -dy, dx current = 1 - current next_x = x next_y = y x = next_x y = next_y if missing == 0: t[x][y] = 1 - t[x][y] break # dog += 1 # if dog > 50: # break dump(t) if __name__ == "__main__": main() |