Exemplo n.º 1
0
def main():
    lines = stripped_lines(sys.stdin)
    numcases = int(lines.next())

    for i in range(numcases):
        size = ints(lines.next())[0]
        pattern = [ints(line) for line in islice(lines, size)]

        result = 'YES' if possible(pattern) else 'NO'

        print 'Case #%d: %s' % (i + 1, result)
Exemplo n.º 2
0
def main():
    lines = stripped_lines(sys.stdin)
    numcases = int(lines.next())

    for i in range(numcases):
        numchests = ints(lines.next())[1]
        starting_keys = ints(lines.next())
        chest_lines = (ints(line) for line in islice(lines, numchests))
        chests = [(chest_line[0], set(chest_line[2:]))
                  for chest_line in chest_lines]

        result = solve(starting_keys, chests)
        output = ' '.join(map(str, result)) if result else 'IMPOSSIBLE'
        print 'Case #%d: %s' % (i + 1, output)
Exemplo n.º 3
0
def main():
    lines = stripped_lines(sys.stdin)
    numcases = int(lines.next())

    for i in range(numcases):
        start, stop = ints(lines.next())

        total = solve(start, stop)

        print 'Case #%d: %s' % (i + 1, total)
Exemplo n.º 4
0
def main():
    lines = stripped_lines(sys.stdin)
    numcases = int(lines.next())

    for i in range(numcases):
        start, stop = ints(lines.next())

        total = solve(start, stop)

        print 'Case #%d: %s' % (i + 1, total)
Exemplo n.º 5
0
def main():
    fin_name = sys.argv[1]
    with open(fin_name) as fin:
        lines = stripped_lines(fin)

        numcases = int(lines.next())

        for caseno in range(1, numcases + 1):
            a, b = ints(lines.next())
            result = solve(a, b)

            outstr = 'Case #%d: %s' % (caseno, result)
            print outstr
Exemplo n.º 6
0
#                           random_combination, random_combination_with_replacement, nth_product nth_permutation nth_combination
# Wrapping                  always_iterable, always_reversible, consumer, with_iter, iter_except
# Others                    locate, rlocate, replace, numeric_range, side_effect, iterate, difference, make_decorator, SequenceView, time_limited, consume, tabulate, repeatfunc

from utils import lmap, flatten, ints, words, fst, snd, parse_line, LETTERS, CONSONANTS, VOWELS, new_table, transposed, rotated

total = 0
all_nums = []
result = []
table = new_table(None, width=3, height=4)

length = 25

for i, line in enumerate(fileinput.input()):
    line = line.strip()
    nums = ints(line)
    data = parse_line(r'', line)

    if len(result) == length:
        num = nums[0]
        r_set = set(result)
        valid = False
        for n in r_set:
            if n >= num:
                continue
            if (num - n) in (r_set - {n}):
                # valid
                valid = True
                break
        if not valid:
            invalid = num
Exemplo n.º 7
0
import os.path
import utils
INPUT = os.path.join(os.path.dirname(__file__), "input.txt")
with open(INPUT) as f:
    data = f.read()

for i, in utils.ints(data):
    for j, in utils.ints(data):
        if i + j == 2020:
            print(i * j)

for i, in utils.ints(data):
    for j, in utils.ints(data):
        for k, in utils.ints(data):
            if i + j + k == 2020:
                print(i * j * k)
Exemplo n.º 8
0
#!/usr/bin/env python3

import sys
sys.path.insert(0, '../common')
from utils import ints

lines = open(sys.argv[1]).read().splitlines()
timestamp = int(lines[0])
times = ints(lines[1])


def find_bus():
    t = timestamp
    while True:
        for bus in times:
            if t % bus == 0:
                return (t, bus)
        t += 1


t, bus = find_bus()
print((t - timestamp) * bus)