from copy import deepcopy parser = argparse.ArgumentParser() parser.add_argument("--from-std-in", action='store_true', default=False) args = parser.parse_args() if args.from_std_in: raw_input = clipboard.paste() else: with open("input.txt", "r") as f: raw_input = f.read() raw_input = raw_input.strip() input = ( Input(raw_input) # .all() # .ints() # .int_tokens() # .tokens() .lines() # .line_tokens() # .line_tokens(sep = "\n", line_sep = "\n\n") ) def parse_potential_ingredients(row, potential_allergen_ingredients, all_ingredients, ingredient_counts): ingredients_str, allergens_str = row.split(" (contains ") ingredients = ingredients_str.split(" ") allergens = allergens_str[:-1].split(", ") for allergen in allergens: if not allergen in potential_allergen_ingredients:
parser = argparse.ArgumentParser() parser.add_argument("--from-std-in", action='store_true', default=False) args = parser.parse_args() if args.from_std_in: raw_input = clipboard.paste() else: with open("input.txt", "r") as f: raw_input = f.read() raw_input = raw_input.strip() input = ( Input(raw_input) # .all() # .ints() # .int_tokens() # .tokens() # .lines() # .line_tokens() .line_tokens(sep="\n", line_sep="\n\n")) GRID_SIZE = 10 def print_grid(grid): for row in grid: for char in row: print(char, end="") print() def rotate_grid_clockwise(grid):
from copy import deepcopy import nltk parser = argparse.ArgumentParser() parser.add_argument("--from-std-in", action='store_true', default=False) args = parser.parse_args() if args.from_std_in: raw_input = clipboard.paste() else: with open("input.txt", "r") as f: raw_input = f.read() raw_input = raw_input.strip() input = ( Input(raw_input).all() # .ints() # .int_tokens() # .tokens() # .lines() # .line_tokens() # .line_tokens(sep = "\n", line_sep = "\n\n") ) def solve_nltk(input): nltk_grammar_str = input.split("\n\n")[0].replace(":", " ->") grammar = nltk.CFG.fromstring(nltk_grammar_str) print(grammar) parser = nltk.ChartParser(grammar)
from functools import reduce from copy import deepcopy parser = argparse.ArgumentParser() parser.add_argument("--from-std-in", action='store_true', default=False) args = parser.parse_args() if args.from_std_in: raw_input = clipboard.paste() else: with open("input.txt", "r") as f: raw_input = f.read() raw_input = raw_input.strip() input = ( Input(raw_input) # .all() .ints() # .int_tokens() # .tokens() # .lines() # .line_tokens() # .line_tokens(sep = "\n", line_sep = "\n\n") ) def solve(input): key1 = input[0] key2 = input[1] cached = defaultdict(lambda: {0: 1})