def test_move(): start = nums("389125467") assert labels_after_1(nth(iterate(move, start), 10)) == "92658374" assert labels_after_1(nth(iterate(move, start), 100)) == "67384529"
def part2(start): circle = nums_1m(nums(start)) for i in range(10_000): circle = nth(iterate(move, circle), 1000) print(i)
def labels_after_1(circle): where = circle.index(1) rotated = circle[where + 1:] + circle[:where] return strs(rotated) def test_move(): start = nums("389125467") assert labels_after_1(nth(iterate(move, start), 10)) == "92658374" assert labels_after_1(nth(iterate(move, start), 100)) == "67384529" if __name__ == '__main__': start = nums("469217538") ans = labels_after_1(nth(iterate(move, start), 100)) print(f"Part 1: labels after 1 are {ans}") # Part 2: let's try just running it. def nums_1m(s, n=1_000_000): start = nums(s) next1 = max(start) + 1 start.extend(range(next1, next1 + (n - len(start)))) return start def test_nums_1m(): n1m = nums_1m("469217538") assert len(n1m) == 1_000_000
def part2(fname): seats = Seats.from_file(fname) final = fix_point(iterate(Seats.next, seats)) return num_occupied(final.seats)
def generations(cells): return iterate(next_gen, cells)
def partn(cells): cells6 = nth(iterate(next_genn_targeted, cells), 6) return len(cells6)
def generations2(cells): return iterate(next_gen2, cells)