def main(): prompt = inp.parse_file_str() # parses the input into a list of row rows = [x for x in range(0, 128)] cols = [x for x in range(0, 8)] results = [] for boarding in prompt: possible_row = rows possible_col = cols row = boarding[0:7] col = boarding[ 7:] # i legit feel like im cheating by using python list slicing for chara in row: if chara == 'F': possible_row = possible_row[:(len(possible_row)) // 2] else: possible_row = possible_row[(len(possible_row)) // 2:] for chara in col: if chara == 'L': possible_col = possible_col[:(len(possible_col)) // 2] else: possible_col = possible_col[(len(possible_col)) // 2:] row = possible_row[0] col = possible_col[0] results.append(row * 8 + col) print(max(results)) for i in results: if i + 2 in results and i + 1 not in results: print(i + 1) exit(11037) # you know the drill
def main2(): all_ingredients = set([]) allergens = {} instream = inp.parse_file_str() for food in instream: ingredients = set(food.split('(')[0].strip().split(' ')) # all_ingredients |= ingredients aller = food.split('(')[1][9:].split(',') aller = [a.strip(' ').strip(')') for a in aller] for a in aller: if a in allergens.keys(): allergens[a] = allergens[a].intersection(ingredients) else: allergens[a] = ingredients ret = [] while len(allergens.keys()): short = shortest(allergens) #print(f'Shortest = {short} with list {allergens[short]}') for allergen in allergens.keys(): if allergen != short: allergens[allergen] -= allergens[short] ret.append((short, allergens[short].pop())) del allergens[short] print(ret) print(sorted(ret, key=lambda x: x[0])) actual_ret = [x[1] for x in sorted(ret, key=lambda x: x[0])] print(actual_ret) actual_actual_ret = ','.join(list(actual_ret)) return actual_actual_ret
def main(): instream = inp.parse_file_str() instructions = [] for direction in instream: instructions.append((direction[0], int(direction[1:]))) x = 0 y = 0 theta = 0 for move in instructions: if move[0] == 'N': y += move[1] elif move[0] == 'S': y -= move[1] elif move[0] == 'E': x += move[1] elif move[0] == 'W': x -= move[1] elif move[0] == 'L': theta += move[1] theta = theta % 360 elif move[0] == 'R': theta -= move[1] theta = theta % 360 elif move[0] == 'F': if theta == 0: # E x += move[1] elif theta == 90: y += move[1] elif theta == 180: x -= move[1] elif theta == 270: y -= move[1] return abs(x) + abs(y)
def main(): all_ingredients = set([]) allergens = {} instream = inp.parse_file_str() ans = 0 for food in instream: ingredients = set(food.split('(')[0].strip().split(' ')) # all_ingredients |= ingredients aller = food.split('(')[1][9:].split(',') # print(aller) aller = [a.strip(' ').strip(')') for a in aller] # print(aller) for a in aller: if a in allergens.keys(): allergens[a] = allergens[a].intersection(ingredients) else: allergens[a] = ingredients safe = all_ingredients - set().union(*[a for a in allergens.values()]) # print(set().union(*[a for a in allergens.values()])) # print(allergens) everything = ' ' + ''.join(instream).replace(')', ' ').replace( '(', '').replace('\n', ' ') # ay carumba # print(everything) # print(safe) for ing in safe: ans += everything.count(' ' + ing + ' ') return ans
def main(): prompt = inp.parse_file_str() valid = 0 for pw in prompt: # valid+= check_pw_part1(pw) valid += check_pw_part2(pw) print('{} passwords are fine'.format(valid)) exit(11037) # im quirky and exit code 0 is for losers
def main(): instream = inp.parse_file_str() # sure it's infinite, but it's easier for me to just define it as finite. play_field = init_play_field(instream) for round_num in range(6): print(f'round {round_num}') play_field = run_one_round(play_field) #print_state(play_field) return count_active(play_field)
def main(): instream = inp.parse_file_str() base_time = int(instream[0]) busses = instream[1].split(',') best = (0, 9999999999999999999999999999999999999) for bus in busses: if bus != 'x': cycletime = int(bus) while cycletime <= base_time: cycletime += int(bus) if cycletime - base_time < best[1]: best = (bus, cycletime - base_time) return best
def main(): instream = inp.parse_file_str() board = [] for row in instream: board.append(list(row)) while True: dupe_check = run_one_round(board) if dupe_check == board: break else: board = dupe_check occupied = 0 for row in board: for seat in row: if seat == '#': occupied += 1 return occupied
def main2(): instream = inp.parse_file_str()[1] busses = instream.split(',') # i just did this in crypto lol a_s = [] n_s = [] for bus in busses: if bus == 'x': continue # print(f'x = {-busses.index(bus)} mod {bus}') a_s.append(-(busses.index(bus))) n_s.append(int(bus)) return crt(a_s, n_s)
def main(): prompt = inp.parse_file_str() # parses the input into a list of rows height = len(prompt) # how high is the input ans = 1 slopes = [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] for slope in slopes: trees = 0 x, y = 0, 0 dx, dy = slope while y < height - 1: x += dx x %= len(prompt[1]) # i love u modulo y += dy if prompt[y][x] == '#': trees += 1 print('{} trees hit on slope {}'.format(trees, slope)) ans *= trees print('answer is {}'.format(ans)) exit(11037) # im quirky and exit code 0 is for losers
def main2(): instream = inp.parse_file_str() instructions = [] for direction in instream: instructions.append((direction[0], int(direction[1:]))) ship_x = 0 ship_y = 0 way_x = 10 way_y = 1 theta = math.degrees(math.atan2(way_y, way_x)) for move in instructions: if move[0] == 'N': way_y += move[1] elif move[0] == 'S': way_y -= move[1] elif move[0] == 'E': way_x += move[1] elif move[0] == 'W': way_x -= move[1] elif move[0] == 'L' or move[0] == 'R': dt = math.radians(move[1]) if move[0] == 'R': dt = -dt newx = (way_x - ship_x) * round( math.cos(dt)) - (way_y - ship_y) * round(math.sin(dt)) + ship_x newy = (way_y - ship_y) * round( math.cos(dt)) + (way_x - ship_x) * round(math.sin(dt)) + ship_y way_x = newx way_y = newy elif move[0] == 'F': dx = way_x - ship_x dy = way_y - ship_y ship_x += dx * move[1] ship_y += dy * move[1] way_x += dx * move[1] way_y += dy * move[1] return abs(ship_x) + abs(ship_y)
def main2(): instream = inp.parse_file_str() ans = 0 for eq in instream: ans += evaluate_eq2(eq) return ans