示例#1
0
def load_data():
    def prepare(line):
        start, stop = map(int, line.split('-'))
        return slice(start, stop + 1)  # ranges in data source are inclusive

    with open(find_data_file()) as f:
        return [prepare(line) for line in f]
示例#2
0
def main1():
    starting_pw = 'abcdefgh'
    scram = Scrambler(starting_pw)

    with open(find_data_file()) as f:
        for line in f:
            scram.parse(line)

    print('PART 1 RESULT:', ''.join(scram.pw))
示例#3
0
def main2():
    ending_pw = 'fbgdceah'
    scram = Scrambler(ending_pw, reverse=True)

    with open(find_data_file()) as f:
        for line in reversed(f.readlines()):
            scram.parse(line)

    # abdfcgeh WRONG
    # hdegabfc WRONG
    print('PART 2 RESULT:', ''.join(scram.pw))
示例#4
0
def main2():
    # Keypad looks like this now
    #     1
    #   2 3 4
    # 5 6 7 8 9
    #   A B C
    #     D
    with open(find_data_file()) as f:
        data = f.read().splitlines()

    result = generate_bathroom_code2(data)
    print('bathroom code is actually', result)
示例#5
0
def load_data():
    fpath = find_data_file()
    for line in open(fpath, 'r'):
        yield line.strip()
示例#6
0
def triangles_by_row():
    with open(find_data_file(), 'r') as f:
        for line in f:
            line = line.strip().split()
            yield map(int, line)
示例#7
0
def main1():
    with open(find_data_file()) as f:
        data = f.read().splitlines()

    result = generate_bathroom_code(data)
    print('bathroom code is', result)