this post was submitted on 13 Nov 2025
3 points (63.6% liked)

Advent Of Code

1122 readers
2 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 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

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 8: The Art of Connection

  • 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 2 days ago

Scheme/Guile

Takes about 5 seconds.

(import (rnrs io ports (6))
        (srfi srfi-1))
#!curly-infix

(define (parse-file file-name)
  (let ((sequence (map string->number (string-split (string-trim-both (call-with-input-file file-name get-string-all)) #\,))))
    (zip sequence (cdr sequence))))

(let loop ((sequence (parse-file "notes/everybody_codes_e2025_q08_p1.txt")) (count 0))
  (if (null? sequence)
      (format #t "P1 Answer: ~a\n\n" count)
      (loop (cdr sequence) (+ count (if (and last (eq? (modulo (- (cadar sequence) (caar sequence)) 32) 16)) 1 0)))))

(define (crosses-over? a b)
  (let ((a1 (car a))
        (a2 (cadr a))
        (b1 (car b))
        (b2 (cadr b)))
    (let ((a2 (modulo {a2 - a1} 256))
          (b1 (modulo {b1 - a1} 256))
          (b2 (modulo {b2 - a1} 256)))
      (and (not (eq? b1 0)) (not (eq? b2 0))
      (or
        (and {b1 < a2} {b2 > a2})
        (and {b1 > a2} {b2 < a2}))))))
(define (count-cross-overs sequence a)
  (let loop ((sequence sequence) (count 0))
    (if (null? sequence)
        count
        (loop (cdr sequence) (+ count (if (crosses-over? (car sequence) a) 1 0))))))
(let loop ((sequence (parse-file "notes/everybody_codes_e2025_q08_p2.txt")) (passed '()) (count 0))
  (if (null? sequence)
      (format #t "P2 Answer: ~a\n\n" count)
      (loop (cdr sequence) (cons (car sequence) passed) (+ count (count-cross-overs passed (car sequence))))))


(let ((sequence (parse-file "notes/everybody_codes_e2025_q08_p3.txt")))
  (let loop ((i 1) (greatest 0))
    (if {i > 256}
        (format #t "P3 Answer: ~a\n\n" greatest)
        (loop (1+ i) (max greatest (let loop ((j i) (greatest 0))
              (if {j > 256}
                  greatest
                  (loop (1+ j) (max greatest (count-cross-overs sequence (list i j)))))))))))