-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleetcode.py
More file actions
39 lines (34 loc) · 1.08 KB
/
Copy pathleetcode.py
File metadata and controls
39 lines (34 loc) · 1.08 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
import inspect
from template import Solution
from pprint import PrettyPrinter
def adj4(x: int, y: int):
yield x, y - 1
yield x + 1, y
yield x, y + 1
yield x - 1, y
def adj8(x: int, y: int):
for y_d in (-1, 0, 1):
for x_d in (-1, 0, 1):
if y_d == x_d == 0:
continue
yield x + x_d, y + y_d
def main() -> None:
pp = PrettyPrinter(indent=2).pprint
for func, _ in inspect.getmembers(Solution(), predicate=inspect.ismethod):
if func.startswith('_'):
continue
print(f'==================[Solution.{func}]===================', end='\n')
while True:
try:
raw_input = input().strip()
if not raw_input:
break
if raw_input.startswith('#') or raw_input.startswith("/*"):
continue
args = __import__('ast').literal_eval(raw_input)
pp(getattr(Solution(), func)(*args))
except EOFError:
break
break
if __name__ == '__main__':
main()