Exemplo n.º 1
0
def main2():
    instream = inp.parse_file_two_newline()
    squares.clear()
    edges.clear()
    ans = 0
    num_squares = 0
    for sq in instream:
        register_square(sq)
        num_squares += 1
    pairs = find_pairs()
    corners = []
    # corners only appear twice!
    for sq in squares.keys():
        occ = 0
        for pair in pairs:
            if sq in pair:
                occ += 1
        if occ == 2:
            corners.append(sq)
    assembled = assemble(corners, pairs)
    print(assembled)
    pic = full_picture(assembled)[:-1]
    num_monsters = look_for_monsters(pic)
    # we actually have to create the image :(
    pounds_per_monster = 15
    print(num_monsters)
    print(len(pic.split('\n')))
    return len(find(''.join(pic), '#')) - num_monsters * pounds_per_monster
Exemplo n.º 2
0
def main():
    instream = inp.parse_file_two_newline()
    p1 = [int(x) for x in instream[0].split('\n')[1:]]
    p2 = [int(x) for x in instream[1].split('\n')[1:]]
    while len(p1) > 0 and len(p2) > 0:
        p1, p2 = play_round(p1, p2)
    winner = p1 if len(p1) != 0 else p2
    return score(winner)
Exemplo n.º 3
0
def main():
    prompt = inp.parse_file_two_newline(
    )  # parses the input into a list of rows
    # part 1

    valid = 0
    for passp in prompt:
        if 'byr' in passp and 'iyr' in passp and 'eyr' in passp and 'hgt' in passp \
                and 'hcl' in passp and 'ecl' in passp and 'pid' in passp:
            valid += 1
    print(valid)

    # part 2
    valid = 0
    for passp in prompt:
        if 'byr' in passp and 'iyr' in passp and 'eyr' in passp and 'hgt' in passp \
                and 'hcl' in passp and 'ecl' in passp and 'pid' in passp:
            fields = passp.split(' ')
            passp_data = {}
            for field in fields:
                if field != '':
                    name = field.split(':')[0]
                    value = field.split(':')[1]
                    passp_data[name] = value
            # sorry for this
            if 1920 <= int(passp_data['byr']) <= 2002 and len(
                    passp_data['byr']) == 4:
                if 2010 <= int(passp_data['iyr']) <= 2020 and len(
                        passp_data['iyr']) == 4:
                    if 2020 <= int(passp_data['eyr']) <= 2030 and len(
                            passp_data['eyr']) == 4:
                        height_unit = passp_data['hgt'][-2:]
                        if height_unit in ['cm', 'in']:
                            hgt_meas = int(passp_data['hgt'][:-2])
                            if (height_unit == 'cm' and 150 <= hgt_meas <= 193
                                ) or (height_unit == 'in' and 59 <= hgt_meas <=
                                      76):  # short people aren't valid i guess
                                if check_hair(passp_data['hcl']):
                                    if passp_data['ecl'] in VALID_EYES:
                                        if check_pid(passp_data['pid']):
                                            valid += 1
    print(valid)
    exit(11037)  # this is a danganronpa reference sorry
Exemplo n.º 4
0
def main():
    prompt = inp.parse_file_two_newline(
    )  # refactored because connor told me to <3
    ans = 0
    for question in prompt:
        ans += len(set(question))
    print(ans)

    # part two
    prompt = inp.parse_file_questionaire(
    )  # not so lucky with this one, need to keep line breaks
    ans = 0
    for group in prompt:
        for question in the_alphabet:
            if checkq(group, question):
                ans += 1

    print(ans)
    exit(11037)  # you know the drill
Exemplo n.º 5
0
def main():
    instream = inp.parse_file_two_newline()
    ans = 0
    num_squares = 0
    for sq in instream:
        register_square(sq)
        num_squares += 1

    pairs = find_pairs()
    corners = []
    # corners only appear twice!
    for sq in squares.keys():
        occ = 0
        for pair in pairs:
            if sq in pair:
                occ += 1
        if occ == 2:
            corners.append(sq)
    print(corners)
    return corners[0] * corners[1] * corners[2] * corners[3]
Exemplo n.º 6
0
def main2():
    instream = inp.parse_file_two_newline()
    p1 = [int(x) for x in instream[0].split('\n')[1:]]
    p2 = [int(x) for x in instream[1].split('\n')[1:]]
    winner = play_recursive_combat(p1, p2, True)
    return score(winner)