def run(): grid = Grid(1000, 1000) for claim in load_input( os.path.join(os.path.dirname(__file__), 'input.txt')): grid.plot_claim(Claim.parse(claim)) return grid.total_overlaps()
def run(): frequency = 0 for line in load_input(os.path.join(os.path.dirname(__file__), 'input.txt')): frequency += int(line) return frequency
def run(): data = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) program = Program.parse([0, 0, 0, 0, 0, 0], data) program.execute() return program.registers[0]
def run(): input = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) shifts = GuardShift.build_shifts([Event.parse(event) for event in input]) # Get the total number of minutes slept by each guard guards = {} for shift in shifts: if shift.guard not in guards: guards[shift.guard] = 0 guards[shift.guard] += shift.get_total_minutes_asleep() # Find the guard with the most minutes slept laziest_guard = None for guard, minutes_slept in guards.items(): if laziest_guard is None or laziest_guard[1] < minutes_slept: laziest_guard = (guard, minutes_slept) # Find out which minute the laziest guard was asleep the most often minutes = {} for shift in shifts: if shift.guard == laziest_guard[0]: for i in range(0, 60): minutes[i] = 0 if i not in minutes else minutes[ i] + shift.was_sleeping_at_minute(i) most_lazy_minute = None total_shifts_asleep_for_current_minute = 0 for minute, shifts_asleep_at_minute in minutes.items(): if most_lazy_minute is None or shifts_asleep_at_minute > total_shifts_asleep_for_current_minute: most_lazy_minute = minute total_shifts_asleep_for_current_minute = shifts_asleep_at_minute return most_lazy_minute * laziest_guard[0]
def run(): data = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) grid = Grid.parse(data) settled, _ = grid.run() return settled
def run(): stars = [ Star.parse(line) for line in load_input( os.path.join(os.path.dirname(__file__), 'input.txt')) ] sky = Sky(stars) return sky.draw_stars()
def run(): data = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) sample_processor = SampleProcessor.parse(data) program = Program.parse(data) program.run(sample_processor.discover_op_codes()) return program.get_final_state()[0]
def run(): two = 0 three = 0 for line in load_input(os.path.join(os.path.dirname(__file__), 'input.txt')): occurrences = get_occurrences(line) two += (1 if exactly_x(occurrences, 2) else 0) three += (1 if exactly_x(occurrences, 3) else 0) return two * three
def run(): seen = {0} frequency = 0 while True: for line in load_input( os.path.join(os.path.dirname(__file__), 'input.txt')): frequency += int(line) if frequency in seen: return frequency else: seen.add(frequency)
def run(): lines = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) for i in range(0, len(lines)): a = lines[i].strip() for b in lines[i + 1:]: b = b.strip() index = single_differing_index(a, b) if index is not False: return 'Index: %d, A letter: %s, B letter: %s, A: %s, B: %s' % ( index, a[index], b[index], a, b) return 'Nothing :('
def run(): points = load_points(load_input(os.path.join(os.path.dirname(__file__), 'input.txt'))) grid_start = 0 grid_end = 400 threshold = 10000 area = 0 for x in range(grid_start, grid_end + 1): for y in range(grid_start, grid_end + 1): total = 0 for p in points.values(): d = distance(x, y, p.x, p.y) total += d if total < threshold: area += 1 return area
def run(): input = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) shifts = GuardShift.build_shifts([Event.parse(event) for event in input]) guards = {} for shift in shifts: guards[shift.guard] = Guard( shift.guard) if shift.guard not in guards else guards[shift.guard] guards[shift.guard].add_shift(shift) current_record = 0 current_minute = None current_guard = None for guard in guards.values(): guards_record = guard.get_most_slept_minute_with_frequency() if current_guard is None or guards_record[1] > current_record: current_guard = guard current_minute = guards_record[0] current_record = guards_record[1] return current_guard.id * current_minute
def run(): tree = DependencyTree.parse( load_input(os.path.join(os.path.dirname(__file__), 'input.txt'))) return tree.resolve_path()
def run(): data = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) area = Area.parse(data) return area.get_total_resource_value_after(1000000000)
parser.add_argument('--wait_time', type=int, default=1) parser.add_argument('--distance_to_coi', type=int, default=1) parser.add_argument('--distance_to_start', type=int, default=1) parser.add_argument('--file', type=str, default='a') params = parser.parse_args() file_dict = { 'a': 'a_example', 'b': 'b_should_be_easy', 'c': 'c_no_hurry', 'd': 'd_metropolis', 'e': 'e_high_bonus', } FILE = file_dict[params.file] loaded_input = loader.load_input('inputs/{}.in'.format(FILE)) definition = loaded_input.definition rides = loaded_input.rides center = (int(definition.rows / 2.0), int(definition.columns / 2.0)) print('Scheduling {} rides on {} cars for bonus {}'.format( len(rides), definition.vehicles, definition.bonus)) # initialize cars = [Car() for i in range(loaded_input.definition.vehicles)] indexed_rides = dict() for ride in rides: indexed_rides[ride.index] = ride # schedule
def morph_segment(image, structure): labels = [] for i in range(image.shape[0]): segmentation = image[i] > 0 segmentation = morph.binary_opening(segmentation, structure=structure) segmentation = morph.binary_fill_holes(segmentation, structure=structure) labels.append(segmentation) return np.array(labels) if __name__ == "__main__": input_path = "./Data/normalized/" output_path = "./Data/output/" classes = 0 images, slice_image, t2images, labels, names, dsos = loader.load_input( input_path, classes, channels=False) print(names[0]) for image4d, Name, dso in zip(images, names, dsos): for size in [1, 2, 3, 4, 5]: labels = [] for image3d in image4d: segmentation = morph_segment(image3d, create_circle(size)) label_mask, no_features = ndimage.label( segmentation, structure=ndimage.generate_binary_structure(3, 2)) max_mask = 0 max_i = 0 for i in range(1, no_features + 1): count = np.count_nonzero(label_mask == i) if count > max_i: max_i = count
def run(): data = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) state = PlantSimulator.load(data, Matcher.load(data)) return state.get_score(50000000000)
def run(): data = load_input(os.path.join(os.path.dirname(__file__), 'input.txt')) sp = SampleProcessor.parse(data) return sp.get_num_samples_with_n_or_more_possible_methods(3)
def run(): tree = DependencyTree.parse( load_input(os.path.join(os.path.dirname(__file__), 'input.txt'))) path, time = tree.resolve_for_workers(5, 60) return time
def run(): points = load_points( load_input(os.path.join(os.path.dirname(__file__), 'input.txt'))) return Grid(points).get_largest_area()