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

Advent Of Code

1199 readers
1 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
 

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
[โ€“] vole@lemmy.world 2 points 1 month ago

maaath

Scheme/Guile

(import (rnrs io ports (6)))

(define (parse-file file-name)
       (map string->number (string-split (call-with-input-file file-name get-string-all) #\newline)))

(let* ((gears (parse-file "notes/everybody_codes_e2025_q04_p1.txt")))
  (format #t "P1 Answer: ~a\n\n" (* 2025 (/ (car gears) (car (last-pair gears))))))


(let* ((gears (parse-file "notes/everybody_codes_e2025_q04_p2.txt")))
  (format #t "P2 Answer: ~a\n\n" (ceiling (* 10000000000000 (/ (car (last-pair gears)) (car gears))))))


(define (parse-file-p3 file-name)
       (map
              (lambda (line) (map string->number(string-split line #\|)))
              (string-split (call-with-input-file file-name get-string-all) #\newline)))
(let* ((gears (parse-file-p3 "notes/everybody_codes_e2025_q04_p3.txt")))
  (format #t "P2 Answer: ~a\n\n"
          (floor (* 100
             (apply * (map (lambda (gear) (if (= 1 (length gear)) 1 (/ (cadr gear) (car gear)))) gears))
             (/ (caar gears) (caar (last-pair gears)))))))