Exemplo n.º 1
0
import functools
from sortedcontainers import SortedList, SortedDict, SortedSet
import itertools
import u
import math
import time
import operator


def a():
    s = 0
    for line in lines:
        xs = u.ints(line)
        d = max(xs) - min(xs)
        s += d
    return s


def b():
    s = 0
    for line in lines:
        for p in itertools.combinations(u.ints(line), 2):
            y, x = min(p), max(p)
            d, r = divmod(x, y)
            if r == 0:
                s += d
    return s


u.main(a, b, submit=globals().get('submit', False))
Exemplo n.º 2
0
        if expected == csum:
            s += sector
    return s


def b():
    real = []
    for line in lines:
        l = line.split("-")
        ename, meta = l[:-1], l[-1]
        sector, csum = meta[:-1].split("[")
        sector = int(sector)
        counter = Counter(sorted("".join(ename)))
        expected = "".join(c for c, _ in counter.most_common(5))
        if expected == csum:
            real.append((ename, sector))
    for ename, sector in real:
        tr = []
        for i, letter in enumerate(string.ascii_lowercase):
            tr.append(
                string.ascii_lowercase[(i + sector) % len(string.ascii_lowercase)]
            )
        table = str.maketrans(string.ascii_lowercase, "".join(tr))
        name = " ".join(ename).translate(table)
        if name.startswith("northpole"):
            return sector
    pass


u.main(a, b, submit=globals().get("submit", False))