-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
95 lines (79 loc) · 2.04 KB
/
template.py
File metadata and controls
95 lines (79 loc) · 2.04 KB
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
88
89
90
91
92
93
94
95
import numpy as np
import re
import pathlib
import json
from functools import reduce, cmp_to_key
from string import ascii_lowercase
from math import prod, gcd, sqrt
from itertools import permutations, product
from llist import dllist as llist
from copy import deepcopy
from hashlib import md5, sha256
from os import environ
def read():
with open(DIR / "input") as f:
s = (f.read() if teststr == "" else teststr).splitlines()
return lmap(lambda r: lmap(int, r.split("\t")), s)
def maybeint(line):
try:
return int(line)
except:
return line
mv = [
(-1, 0), # U
(1, 0), # D
(0, -1), # L
(0, 1), # R
(-1, 1), # UR
(1, 1), # DR
(-1, -1), # UL
(1, -1), # DL
]
mv_3d = [
(-1, 0, 0), # U
(1, 0, 0), # D
(0, -1, 0), # L
(0, 1, 0), # R
(0, 0, -1), # B
(0, 0, 1), # F
]
def BFS(start, can_walk, goal, cost_fn=None):
cost_fn = (lambda _, __: 1) if cost_fn is None else cost_fn
options = [(start, 0)]
visited = set([start])
while options:
new_o = []
for pos, cost in options:
for d in mv:
new_p = (pos[0] + d[0], pos[1] + d[1])
if new_p[0] < 0: # lower bound check
continue
if new_p[1] < 0: # lower bound check
continue
try:
assert can_walk(pos, new_p)
except:
continue # upper bound check
if new_p in visited:
continue
visited.add(new_p)
cost_ = cost + cost_fn(pos, new_p)
new_o.append((new_p, cost_))
if goal(new_p):
return cost_
options = new_o
return None
def easy():
print(t)
def hard():
return
teststr = """"""
if environ.get("AOC_SOLVE", "") == "1":
teststr = ""
DIR = pathlib.Path(__file__).parent.absolute()
lmap = lambda *a: list(map(*a))
inf = float("inf")
t = read()
if __name__ == "__main__":
easy()
hard()