def get_num_distinct_groups(data): res = set() all_progs = set(data) num_groups = 0 while remaining := all_progs - res: num_groups += 1 res |= get_connected(data, first(remaining))
def from_str(cls, s): """lhrml (164) -> ecblhee, sdjshz""" l, *r = s.split(' -> ') name, weight = l.split() if r: fs = frozenset(first(r).split(', ')) else: fs = frozenset() return cls(name, int(weight.replace('(').replace(')')), fs)
def write(self, filename: str = None) -> str: if filename is None: filename = self.params['outfile'] best = first(self.model_scores().values()) model_name = best['name'] ids = self.to_IDs(self.data['X_test']) predictions = self.predict(dataframe=self.data['X_test'], model_name=model_name)[model_name] submission = pd.DataFrame({ self.params['Y_field']: predictions }, index=ids).round(2) csv_text = submission.to_csv() with open(filename, "w") as file: file.write(csv_text) print(f'Wrote: {filename}') return filename
def main(): input_ = load_from_file("day13_input.txt") # PART 1 earliest_ts = int(input_[0]) bus_ids = parse_ints(input_[1]) wait_times = [] for id_ in bus_ids: first_larger = first((i for i in count(start=0, step=id_) if i >= earliest_ts)) wait_times.append(first_larger - earliest_ts) min_wait = min(wait_times) sol_pt1 = min_wait * bus_ids[wait_times.index(min_wait)] print(sol_pt1) assert sol_pt1 == 2382 # Solution for my input # PART 2 sol_pt2 = solve_pt2(parse_ints_pt2(input_[1])) print(sol_pt2) assert sol_pt2 == 906332393333683 # Solution for my input
def aoc19(network): cur_pos, cur_val = first(network.items()) cur_dir = Direction.down letter_path = [] target_letters = set(string.ascii_uppercase) & set(network.values()) straight = set('-|') | target_letters for step_total in count(1): if cur_val in straight: # continue straight if cur_val in target_letters: letter_path.append(cur_val) if cur_pos + cur_dir.value not in network: return ''.join(letter_path), step_total elif cur_val == '+': # turn for v in 0, 1: next_dir = cur_dir.rotated(v) if cur_pos + next_dir.value in network: cur_dir = next_dir break cur_pos += cur_dir.value cur_val = network[cur_pos]
def summary(self) -> Tuple[float, str, str, str]: best = first(self.model_scores().values()) # return ( best['RMSLE'], best ) return (best['RMSLE'], best['class'], best['name'], " ".join(best['features']))
def get_square_side(data): return first(i for i in count(1, 2) if i**2 >= data)
def populate_wire_points(w: Wire): points = (p for l in w for p in l.range(list)) # remove side-by-side dupes return tuple(first(p) for p in groupby(points))
def test_interpose(): assert "a" == first(rest(interpose("a", range(1000000000)))) assert "tXaXrXzXaXn" == "".join(interpose("X", "tarzan")) assert list(interpose(0, itertools.repeat(1, 4))) == [1, 0, 1, 0, 1, 0, 1] assert list(interpose(".", ["a", "b", "c"])) == ["a", ".", "b", ".", "c"]
def test_interpose(): assert "a" == first(rest(interpose("a", range(1000000000)))) assert "tXaXrXzXaXn" == "".join(interpose("X", "tarzan")) assert list(interpose(0, itertools.repeat(1, 4))) == [1, 0, 1, 0, 1, 0, 1] assert list(interpose('.', ['a', 'b', 'c'])) == ['a', '.', 'b', '.', 'c']
def test_first(): assert first('ABCDE') == 'A' assert first((3, 2, 1)) == 3 assert isinstance(first({0: 'zero', 1: 'one'}), int)
def test_first(): assert first("ABCDE") == "A" assert first((3, 2, 1)) == 3 assert isinstance(first({0: "zero", 1: "one"}), int)
def aoc07_a(data): """find bottom""" non_head_names = set( chain.from_iterable(map(attrgetter('children'), data.values()))) return first(data.keys() - non_head_names)
def __main(): insts = first(U.read_file(16, 2017)).split(',') print(aoc16_a(insts)) print(aoc16_b(insts))
def _parse_instruction(inst): return first(inst), inst[1:].split('/')
def __main(): data = first(U.read_file(9, 2017)) print(aoc09(data))
from cytoolz.itertoolz import first from collections import deque import pyaoc2019.utils as U __author__ = 'acushner' data = list(map(int, first(U.read_file(1, 2017)))) def aoc01(rotate: int): if rotate is None: rotate = len(data) // 2 d_r = deque(data) d_r.rotate(rotate) return sum(i for i, j in zip(data, d_r) if i == j) def __main(): print(aoc01(1)) print(aoc01(None)) if __name__ == '__main__': __main()
def delay(data, upper=10000000): # TODO: calc using lcm return first(offset for offset in range(upper) if not calc_detections(data, offset))
def aoc07_b(data, start): try: data[start].calc_total_weight(data) except ResultException as e: return first(e.args)
def aoc10_a(): input_lens = [int(e) for e in first(U.read_file(10, 2017)).split(',')] d, total_rotation = apply_rotations(range(256), input_lens) d.rotate(-total_rotation) return d[0] * d[1]
def __main(): data = first(U.read_file(11, 2017)) print(calc_final_dist(data)) print(calc_farthest_dist(data))
def __main(): print(aoc10_a()) print(knot_hash(first(U.read_file(10, 2017))))
def get_data(): return [int(v) for v in first(U.read_file(6, 2017)).split()]