2018/07.py
def part1() -> str:
    """
    I'm solving Part 1 using a BFS-like algorithm. I maintain a *frontier*, effectively
    the set of elements that can be performed next. The rules state if there are
    multiple jobs that can be perfomred at once, the one that is lexicographicaly first
    should be performed. To accomplish this, I'm storing the frontier in a heap so that
    the lexicographicaly first element is always what gets popped of the heap.

    I'm pretty sure some sort of topological sort would also do the trick here.
    """
    frontier = deepcopy(STARTS)
    heapq.heapify(frontier)
    satisfied = set()
    s = ""
    while frontier:
        current = heapq.heappop(frontier)

        # If it's already been satisfied, skip.
        if current in satisfied:
            continue

        # Check to see if all of the current job's dependencies have been satisfied.
        sat = True
        for dep in STEP_DEPENDENCIES[current]:
            if dep not in satisfied:
                sat = False
                break
        if not sat:
            continue

        # Set the current job to satisfied, and add it to the ordering of the steps.
        satisfied.add(current)
        s += current

        # Add all of the jobs that depend on this job to the frontier. (It is fine if
        # they are not fully satisfied because of the sat check above.)
        for sub in STEP_SUBSEQUENTS[current]:
            heapq.heappush(frontier, sub)

    assert len(STEPS) == len(s)
    return s

    I'm solving Part 1 using a BFS-like algorithm. I maintain a *frontier*, effectively
    the set of elements that can be performed next. The rules state if there are
    multiple jobs that can be perfomred at once, the one that is lexicographicaly first
    should be performed. To accomplish this, I'm storing the frontier in a heap so that
    the lexicographicaly first element is always what gets popped of the heap.

    I'm pretty sure some sort of topological sort would also do the trick here.
    
I'm solving Part 1 using a BFS-like algorithm. I maintain a *frontier*, effectively
the set of elements that can be performed next. The rules state if there are
multiple jobs that can be perfomred at once, the one that is lexicographicaly first
should be performed. To accomplish this, I'm storing the frontier in a heap so that
the lexicographicaly first element is always what gets popped of the heap.

I'm pretty sure some sort of topological sort would also do the trick here.
I ' m solving Part 1 using a BFS - like algorithm . I maintain a * frontier * effectively the set of elements that can be performed next . The rules state if there are multiple jobs that can be perfomred at once the one that is lexicographicaly first should be performed . To accomplish this I ' m storing the frontier in a heap so that the lexicographicaly first element is always what gets popped of the heap . I ' m pretty sure some sort of topological sort would also do the trick here .
def part1() -> str:
    frontier = deepcopy(STARTS)
    heapq.heapify(frontier)
    satisfied = set()
    s = ""
    while frontier:
        current = heapq.heappop(frontier)
        if current in satisfied:
            continue
        sat = True
        for dep in STEP_DEPENDENCIES[current]:
            if dep not in satisfied:
                sat = False
                break
        if not sat:
            continue
        satisfied.add(current)
        s += current
        for sub in STEP_SUBSEQUENTS[current]:
            heapq.heappush(frontier, sub)
    assert len(STEPS) == len(s)
    return s
def part1 ( ) -> str : frontier = deepcopy ( STARTS ) heapq . heapify ( frontier ) satisfied = set ( ) s = "" while frontier : current = heapq . heappop ( frontier ) if current in satisfied : continue sat = True for dep in STEP_DEPENDENCIES [ current ] : if dep not in satisfied : sat = False break if not sat : continue satisfied . add ( current ) s += current for sub in STEP_SUBSEQUENTS [ current ] : heapq . heappush ( frontier , sub ) assert len ( STEPS ) == len ( s ) return s
I'm solving Part 1 using a BFS-like algorithm.
I ' m solving Part 1 using a BFS - like algorithm .
"""
    I'm solving Part 1 using a BFS-like algorithm. I maintain a *frontier*, effectively
    the set of elements that can be performed next. The rules state if there are
    multiple jobs that can be perfomred at once, the one that is lexicographicaly first
    should be performed. To accomplish this, I'm storing the frontier in a heap so that
    the lexicographicaly first element is always what gets popped of the heap.

    I'm pretty sure some sort of topological sort would also do the trick here.
    """ # If it's already been satisfied, skip. # Check to see if all of the current job's dependencies have been satisfied. # Set the current job to satisfied, and add it to the ordering of the steps. # Add all of the jobs that depend on this job to the frontier. (It is fine if # they are not fully satisfied because of the sat check above.)