-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.py
49 lines (35 loc) · 1.2 KB
/
template.py
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
#!/usr/bin/env python3
import sys
from collections import defaultdict, Counter, deque
from parse import parse
import re
import math
def extract(s):
return [int(x) for x in re.findall(r'(-?\d+).?', s)]
def vadd(v1, v2):
return tuple([x + y for x, y in zip(v1, v2)])
def ichr(i):
return chr(ord('a') + i)
def iord(c):
return ord(c.lower()) - ord('a')
def optidx(d, opt=max, nth=0):
if not isinstance(d, dict):
d = dict(enumerate(d))
rv = opt(d.values())
return [i for i, v in d.items() if v == rv][nth], rv
LETTERS = "abcdefghijklmnopqrstuvwxyz"
UP, RIGHT, DOWN, LEFT = VDIRS = (0, -1), (1, 0), (0, 1), (-1, 0),
DIRS = {'N': UP, 'E': RIGHT, 'S': DOWN, 'W': LEFT }
ALL_DIRS = [(x, y) for x in [-1,0,1] for y in [-1,0,1] if not x == y == 0]
def turn(v, d='left'):
n = -1 if d == 'left' else 1
return VDIRS[(VDIRS.index(v) + n) % len(VDIRS)]
##############################
def main(args):
file = open(args[1]) if len(args) > 1 else sys.stdin
# data = [x.rstrip('\n').split('\n') for x in file.read().split('\n\n')]
# data = [int(s.rstrip('\n')) for s in file]
data = [s.rstrip('\n') for s in file]
print(data)
if __name__ == '__main__':
main(sys.argv)