Day 3: Lobby

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

  • Chais@sh.itjust.works
    link
    fedilink
    arrow-up
    2
    ·
    26 days ago

    Python

    I had a hunch that part 2 would just be part one with more places and immediately factored that code into a separate method. Overall quite happy with the compact code.

    from functools import partial
    from pathlib import Path
    from typing import List
    
    
    def parse_input(input: str) -> List[List[int]]:
        return [list(map(int, l)) for l in input.splitlines()]
    
    
    def find_highest(bank: List[int], n: int) -> int:
        if n == 1:
            return max(bank)
        rest = bank[bank[:-n+1].index(place := max(bank[:-n+1]))+1:]
        return int(f"{place}{find_highest(rest, n-1)}")
    
    
    def part_one(input: str) -> int:
        bat_banks = parse_input(input)
        return sum(map(partial(find_highest, n = 2), bat_banks))
    
    
    def part_two(input: str) -> int:
        bat_banks = parse_input(input)
        return sum(map(partial(find_highest, n = 12), bat_banks))
    
    
    if __name__ == "__main__":
        input = Path("_2025/_3/input").read_text("utf-8")
        print(part_one(input))
        print(part_two(input))