def load(info): """Initialize the plugin.""" info['apiRoot'].spec = spec.Spec() info['apiRoot'].graph = graph.Graph() ingest() GitHub.addScopes(['user:email', 'public_repo']) events.bind('oauth.auth_callback.after', 'cis', storeToken)
def post(self, src_id): ''' Generate a matrix from the source stored at that ID. Returns metadata for that matrix. ''' try: posted_data = request.get_json(force=True) client = db_client() col = db_collection(client, DATALOADER_DB_NAME, DATALOADER_COL_NAME) try: src = find_source(col, src_id) except IndexError: return 'No resource at that URL.', 404 error, matricesNew = utils.ingest(posted_data, src) if error: return 'Unable to create matrix.', 406 matrices = [] for each in src['matrices']: matrices.append(each) matrices.extend(matricesNew) col.update({'src_id':src_id}, { '$set': {'matrices': matrices} }) except: tb = traceback.format_exc() return tb, 406 return matricesNew, 201
def solve2(): data = ingest(INPUT_FILE) numbers = [int(n) for n in data] TARGET_SUM = 2020 a, b, c = None, None, None for i in range(len(numbers)): for j in range(len(numbers)): for k in range(len(numbers)): if i == j or i == k or j == k: # same index, skip pass else: x, y, z = numbers[i], numbers[j], numbers[k] if x + y + z == TARGET_SUM: a, b, c = x, y, z break if a is None or b is None or c is None: raise Exception('No numbers found that sum to: %s' % TARGET_SUM) else: answer = a * b * c return answer
def solve1(): data = ingest(INPUT_FILE) hill = data m, n = ( len(hill), # "height" of hill, rows len(hill[0]), # "width" of hill, columns ) SLOPE = Slope(3, 1) num_trees_encountered = 0 i, j = (0, 0) while i < m: if hill[i][j] == '#': num_trees_encountered += 1 row = hill[i] i += SLOPE.y j = (j + SLOPE.x) % n answer = num_trees_encountered return answer
def solve2(): data = ingest(INPUT_FILE) entries = data pattern = r'(?P<lower>\d+)-(?P<upper>\d+) (?P<letter>[a-z]): (?P<password>[a-z]+)' regex = re.compile(pattern) num_valid_passwords = 0 for entry in entries: m = regex.match(entry) if m is None: raise Exception('Entry does not match pattern: %s' % entry) else: i, j, letter, password = [ int(m.group('lower')) - 1, int(m.group('upper')) - 1, m.group('letter'), m.group('password'), ] chars = [password[i], password[j]] occurrences = len(list(filter(lambda c: c == letter, chars))) if occurrences == 1: num_valid_passwords += 1 answer = num_valid_passwords return answer
def __init__(self): data = ingest(INPUT_FILE) self.earliest_departure_time = int(data[0]) bus_ids = [int(bid) for bid in data[1].split(',') if bid != 'x'] self.bus_schedule = BusSchedule(bus_ids)
def solve1(): data = ingest(INPUT_FILE) numbers = [int(n) for n in data] TARGET_SUM = 2020 a, b = None, None for i in range(len(numbers)): for j in range(len(numbers)): if i == j: # same index, skip pass else: x, y = numbers[i], numbers[j] if x + y == TARGET_SUM: a, b = x, y break if a is None or b is None: raise Exception('No numbers found that sum to: %s' % TARGET_SUM) else: answer = a * b return answer
def solve2(): data = ingest(INPUT_FILE) hill = data m, n = ( len(hill), # "height" of hill, rows len(hill[0]), # "width" of hill, columns ) slopes = [ Slope(1, 1), Slope(3, 1), Slope(5, 1), Slope(7, 1), Slope(1, 2), ] def _count_trees(slope): num_trees_encountered = 0 i, j = (0, 0) while i < m: if hill[i][j] == '#': num_trees_encountered += 1 row = hill[i] i += slope.y j = (j + slope.x) % n return num_trees_encountered trees = [_count_trees(slope) for slope in slopes] answer = reduce(mul, trees, 1) return answer
def __init__(self): data = ingest(INPUT_FILE, as_oneline=True) self.instructions = data
def __init__(self): data = ingest(INPUT_FILE) self.ingredients = [Ingredient(x) for x in data]
def __init__(self): self.data = ingest(INPUT_FILE) routes = self.data self.graph = Graph(routes)
def __init__(self): data = ingest(INPUT_FILE) self.numbers = [int(n) for n in data]
def __init__(self): self.data = ingest(INPUT_FILE) self.strings = [NaughtyOrNice(s) for s in self.data]
def __init__(self): self.data = ingest(INPUT_FILE, as_groups=True) self.passports = [Passport(lines) for lines in self.data]
def __init__(self): data = ingest(INPUT_FILE, as_groups=True) self.ticket_scanner = TicketScanner(*data)
def __init__(self): self.data = ingest(INPUT_FILE) self.numbers = sorted([int(n) for n in self.data])
def __init__(self): self.data = ingest(INPUT_FILE, as_table=True, cell_func=int)
def __init__(self): data = ingest(INPUT_FILE, as_oneline=True) self.directions = data self.delivery_map = DeliveryMap(self.directions)
def __init__(self): self.data = ingest(INPUT_FILE) self.masses = [int(mass) for mass in self.data]
def __init__(self): self.data = ingest(INPUT_FILE) self.seating_chart = SeatingChart(self.data)
def __init__(self): self.data = ingest(INPUT_FILE) self.rooms = [Room(room) for room in self.data]
def __init__(self): self.data = ingest(INPUT_FILE) self.boarding_pass_seat_ids = [BoardingPass(code).seat_id for code in self.data]
def __init__(self): self.data = ingest(INPUT_FILE)
def __init__(self): self.data = ingest(INPUT_FILE) self.instructions = [ Instruction(instruction) for instruction in self.data ]
def __init__(self): data = ingest(INPUT_FILE, as_oneline=True) self.directions = [ Direction(direction.strip()) for direction in data.split(',') ]
def __init__(self): self.data = ingest(INPUT_FILE) self.ips = [IPV7(ip) for ip in self.data]
def __init__(self): self.data = ingest(INPUT_FILE) self.boxes = [Box(box) for box in self.data]
def __init__(self): self.data = ingest(INPUT_FILE, as_json=True)
def __init__(self): data = ingest(INPUT_FILE) containers = sorted([int(c) for c in data], reverse=True) self.kitchen = Kitchen(containers) self.kitchen.store(TARGET)
def __init__(self): data = ingest(INPUT_FILE, as_oneline=True) self.key = data