Esempio n. 1
0
def ans():
    lines = open(filepath('054.txt')).readlines()
    turns = [line.strip().split() for line in lines]
    num_one_wins = 0
    for cards in turns:
        one = cards[:5]
        two = cards[5:]
        if one_wins(one, two):
            num_one_wins += 1
    return num_one_wins
Esempio n. 2
0
def ans():
    lines = open(filepath('008.txt')).readlines()
    chars = ''.join(x.strip() for x in lines)
    largest = 0
    for i in range(len(chars) - 12):
        product = 1
        for j in range(13):
            product *= int(chars[i + j])
        largest = max(largest, product)
    return largest
Esempio n. 3
0
def ans():

    content = open(filepath('059.txt')).read()
    ordinals = [int(x) for x in content.strip().split(',')]
    encrypted = ''.join([chr(x) for x in ordinals])

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    possible_keys = product(alphabet, repeat=3)

    for key in possible_keys:
        decrypted = decrypt(key, encrypted)
        if contains_common_words(decrypted):
            break

    return sum(ord(c) for c in decrypted)
Esempio n. 4
0
def ans():
    lines = open(filepath('011.txt')).readlines()
    grid = [[int(x) for x in line.split()] for line in lines]
    largest = 0
    for i in range(len(grid)):
        for j in range(len(grid[i])):
            for row_inc, col_inc in [
                (1, 0),  # Vertical
                (0, 1),  # Horizonatal
                (1, 1),  # Diagonal one
                (-1, 1),  # Diagonal two
            ]:
                largest = max(
                    largest,
                    helper(grid, i, j, row_inc, col_inc, 0, 1),
                )
    return largest
Esempio n. 5
0
def max_sum_through_triangle(filename):
    lines = open(filepath(filename)).readlines()
    triangle = tuple([tuple([int(x) for x in line.split()]) for line in lines])
    return helper(triangle, 0, 0)
Esempio n. 6
0
 def generate_filename(self):
     now = datetime.datetime.utcnow()
     self.version = now.strftime("%Y%m%d%H%M%S")
     self.filename = "%s_%s.sql" % (self.version, self.name)
     self.filepath = files.filepath(config.get_migrations_dir(),
                                    self.filename)
Esempio n. 7
0
 def rollback_filepath(self):
     return files.filepath(config.get_rollbacks_dir(),
                           self.rollback_filename())
Esempio n. 8
0
def ans():
    names = sorted(open(filepath('022.txt')).read().split())
    total = 0
    for i, name in enumerate(names):
        total += (i + 1) * get_value(name)
    return total
Esempio n. 9
0
def ans():
    lines = open(filepath('013.txt')).readlines()
    sum_ = sum(int(line.strip()) for line in lines)
    return str(sum_)[:10]
Esempio n. 10
0
        stream.write('{} - {} - {}\n'.format(
            outcome.text + ' ' * (max_outcome_length - len(outcome.name)),
            str(results[outcome][0]).rjust(len(str(total_num_outcomes))),
            format_duration(results[outcome][1]),
        ))

    # Print a dashed line separating outcome totals from absolute totals
    stream.write('-' * outcomes_line_length + '\n')

    # Print absolute totals
    stream.write('{} - {} - {}\n'.format(
        'TOTAL'.ljust(max_outcome_length),
        total_num_outcomes,
        format_duration(sum(x[1] for x in results.values())),
    ))


if __name__ == '__main__':

    try:
        answers = loads(open(filepath('answers.txt')).read())
    except FileNotFoundError:
        answers = {}

    if 1 < len(argv):
        paths = argv[1:]
    else:
        paths = sorted(glob(filepath('[0-9][0-9][0-9].py')))

    check(answers, paths, stdout)