This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L = 10**6 | |
I = [0]*9 | |
z = list(map(int, '523764819')) | |
for c,n in zip(z,z[1:]): | |
I[c-1] = n | |
I[z[-1]-1] = 10 | |
I += list(range(11, L+1)) | |
I += [z[0]] | |
cur = I[-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from functools import reduce | |
from collections import Counter | |
DIRS = ['e', 'se', 'sw', 'w', 'nw', 'ne'] | |
def parse(l): | |
res = [] | |
while l: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from functools import reduce | |
def score(deck): | |
return reduce(lambda x, s: x+s[0]*s[1], enumerate(deck, 1), 0) | |
def play1(deck1, deck2): | |
while deck1 and deck2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from functools import reduce | |
from itertools import product | |
from collections import defaultdict | |
# Return all 8 transformations of the image | |
def tr(l, img): | |
rt = lambda m,_: m+[[[m[-1][l-i-1][j] | |
for i in range(l)] for j in range(l)]] | |
fl = lambda m,_: m+[[[m[-1][l-i-1][j] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def match1(rule, rules, s): | |
for i,r in enumerate(rule): | |
if r[0] == '"': | |
if s and r[1] == s[0]: | |
s = s[1:] | |
else: | |
return False | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from operator import add, mul | |
from re import findall | |
def arg(cont, ts): | |
res, ts = cont(ts[1:]) if ts[0] == '(' else (int(ts[0]), ts) | |
return res, ts[1:] | |
def parse(ops, term, cont, ts): | |
lh, ts = term(cont, ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from operator import add, mul | |
from re import findall | |
def arg(cont, ts): | |
res, ts = cont(ts[1:]) if ts[0] == '(' else (int(ts[0]), ts) | |
return res, ts[1:] | |
def parse(ops, term, cont, ts): | |
lh, ts = term(cont, ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from itertools import product | |
from collections import defaultdict | |
def build(lines, dims): | |
return {(x, y)+(0,)*(dims-2) | |
for x, l in enumerate(lines) | |
for y, v in enumerate(l.strip()) | |
if v == '#'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from re import findall | |
from collections import defaultdict | |
from functools import reduce | |
import operator | |
parts = [[findall('\d+', l) | |
for l in x.split('\n')] | |
for x in stdin.read().split('\n\n')] | |
rules = [[[int(r[i]),int(r[i+1])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
from functools import reduce | |
def play(s,i): | |
stor,l = s | |
j=i-1-stor.get(l,i-1) | |
stor[l]=i-1 | |
return (stor,j) | |
I=[int(i) for i in stdin.readline().split(',')] |
NewerOlder