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]
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))
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))
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)
def load_data(): fpath = find_data_file() for line in open(fpath, 'r'): yield line.strip()
def triangles_by_row(): with open(find_data_file(), 'r') as f: for line in f: line = line.strip().split() yield map(int, line)
def main1(): with open(find_data_file()) as f: data = f.read().splitlines() result = generate_bathroom_code(data) print('bathroom code is', result)