this post was submitted on 03 Dec 2025
26 points (100.0% liked)

Advent Of Code

1199 readers
9 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2025

Solution Threads

M T W T F S S
1 2 3 4 5 6 7
8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 2 years ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[โ€“] Chais@sh.itjust.works 2 points 2 weeks 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))