this post was submitted on 09 Nov 2025
8 points (83.3% liked)

Advent Of Code

1154 readers
39 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

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
 

Quest 4: Teeth of the Wind

  • 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

Link to participate: https://everybody.codes/

you are viewing a single comment's thread
view the rest of the comments
[โ€“] Pyro@programming.dev 2 points 1 week ago (3 children)

Python

# snipped read_input implementation
data = read_input("input_p3.txt")

# part 1 and 2 can be solved using a calculator 
# with only the first and last gears

def part3(data):
    shafts = data.splitlines()

    rotations = 100 * int(shafts[0])
    for shaft in shafts[1:-1]:
        gear1, gear2 = [int(g) for g in shaft.split('|')]
        rotations *= gear2 / gear1
    rotations /= int(shafts[-1])
    
    return int(rotations)

assert part3("""5
7|21
18|36
27|27
10|50
10|50
11""") == 6818

print(part3(data))
[โ€“] reboot6675@sopuli.xyz 2 points 1 week ago (1 children)

Ohh so it was possible to use floats for this! I was "worried" that it would lead to precision errors haha so I ended up "cheating" with BigInt (Golang) to make all the multiplications first and one division at the end

[โ€“] Pyro@programming.dev 2 points 1 week ago

Yeah, it may be possible for precision errors to accumulate in my solution but for EC the inputs are few enough that it doesn't really matter. Maybe I got a little lucky with my input too.

load more comments (1 replies)