2020/22.py
def part1() -> int:
    """
    I decided to use lists for this instead of a queue, because I'm really unfamiliar
    with the stdlib for queues in Python, so it is faster for me to think about lists.
    Also, using a queue in Part 2 would have been a disaster.
    """
    dp1 = deepcopy(DECKP1)
    dp2 = deepcopy(DECKP2)

    # Loop until one player has all the cards.
    tot = len(dp1) + len(dp2)
    while len(dp1) < tot and len(dp2) < tot:
        # Pull of the top of each deck. This is where having pattern matching that isn't
        # terrible would be nice. Or having a Queue in the stdlib that isn't impossible
        # to remember how to use.
        c1, *dp1r = dp1
        c2, *dp2r = dp2

        # Determine who has won, and set their decks accordingly.
        if c1 < c2:
            dp1 = dp1r
            dp2 = dp2r + [c2, c1]
        elif c2 < c1:
            dp1 = dp1r + [c1, c2]
            dp2 = dp2r

    # Reverse so that the lower indexes are associated with the cards at the bottom of
    # the deck (note we are guaranteed at this point than only one of `dp1` or `dp2` has
    # anything in it, so we can just add them together to get the winning deck).
    ans = 0
    for i, x in enumerate(reversed(dp1 + dp2)):
        ans += (i + 1) * x

    return ans

    I decided to use lists for this instead of a queue, because I'm really unfamiliar
    with the stdlib for queues in Python, so it is faster for me to think about lists.
    Also, using a queue in Part 2 would have been a disaster.
    
I decided to use lists for this instead of a queue, because I'm really unfamiliar
with the stdlib for queues in Python, so it is faster for me to think about lists.
Also, using a queue in Part 2 would have been a disaster.
I decided to use lists for this instead of a queue because I ' m really unfamiliar with the stdlib for queues in Python so it is faster for me to think about lists . Also using a queue in Part 2 would have been a disaster .
def part1() -> int:
    dp1 = deepcopy(DECKP1)
    dp2 = deepcopy(DECKP2)
    tot = len(dp1) + len(dp2)
    while len(dp1) < tot and len(dp2) < tot:
        c1, *dp1r = dp1
        c2, *dp2r = dp2
        if c1 < c2:
            dp1 = dp1r
            dp2 = dp2r + [c2, c1]
        elif c2 < c1:
            dp1 = dp1r + [c1, c2]
            dp2 = dp2r
    ans = 0
    for i, x in enumerate(reversed(dp1 + dp2)):
        ans += (i + 1) * x
    return ans
def part1 ( ) -> int : dp1 = deepcopy ( DECKP1 ) dp2 = deepcopy ( DECKP2 ) tot = len ( dp1 ) + len ( dp2 ) while len ( dp1 ) < tot and len ( dp2 ) < tot : c1 , * dp1r = dp1 c2 , * dp2r = dp2 if c1 < c2 : dp1 = dp1r dp2 = dp2r + [ c2 , c1 ] elif c2 < c1 : dp1 = dp1r + [ c1 , c2 ] dp2 = dp2r ans = 0 for i , x in enumerate ( reversed ( dp1 + dp2 ) ) : ans += ( i + 1 ) * x return ans
I decided to use lists for this instead of a queue, because I'm really unfamiliar
with the stdlib for queues in Python, so it is faster for me to think about lists.
I decided to use lists for this instead of a queue because I ' m really unfamiliar with the stdlib for queues in Python so it is faster for me to think about lists .
"""
    I decided to use lists for this instead of a queue, because I'm really unfamiliar
    with the stdlib for queues in Python, so it is faster for me to think about lists.
    Also, using a queue in Part 2 would have been a disaster.
    """ # Loop until one player has all the cards. # Pull of the top of each deck. This is where having pattern matching that isn't # terrible would be nice. Or having a Queue in the stdlib that isn't impossible # to remember how to use. # Determine who has won, and set their decks accordingly. # Reverse so that the lower indexes are associated with the cards at the bottom of # the deck (note we are guaranteed at this point than only one of `dp1` or `dp2` has # anything in it, so we can just add them together to get the winning deck).