this post was submitted on 05 Nov 2025
12 points (92.9% liked)

Advent Of Code

1199 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 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 1: Whispers in the Shell

  • 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 4 points 1 month ago* (last edited 1 month ago)

I'm still learning Scheme, but I wrote a solution in Guile:

(use-modules (ice-9 rdelim ))
(use-modules (srfi srfi-1))

(define (parse-step s) (*
    (if (eq? (string-ref s 0) #\L) -1 1)
    (string->number (substring s 1))
))
(define (parse-file file-name) (begin
  (define p (open-input-file file-name))
  (define names-str (read-line p))
  (read-line p)
  (define steps-str (read-line p))
  (cons
    (string-split names-str #\,)
    (map parse-step (string-split steps-str #\,))
  )
))

(let* ((parsed-file (parse-file "notes/everybody_codes_e2025_q01_p1.txt"))
       (names (car parsed-file))
       (steps (cdr parsed-file)))
  (format #t "names: ~a\nsteps: ~a\n" names steps)
  (define name-count (length names))
  (define chosen-name-idx (reduce
    (lambda (pos change) (max 0 (min (- name-count 1) (+ pos change))))
    0 steps))
  (format #t "P1: Chosen name(~a): ~a\n\n" chosen-name-idx (list-ref names chosen-name-idx))
)

(let* ((parsed-file (parse-file "notes/everybody_codes_e2025_q01_p2.txt"))
       (names (car parsed-file))
       (steps (cdr parsed-file)))
  (format #t "names: ~a\nsteps: ~a\n" names steps)
  (define name-count (length names))
  (define chosen-name-idx (modulo (reduce + 0 steps) name-count))
  (format #t "P2: Chosen name(~a): ~a\n\n" chosen-name-idx (list-ref names chosen-name-idx))
)

(let* ((parsed-file (parse-file "notes/everybody_codes_e2025_q01_p3.txt"))
       (names (list->vector (car parsed-file)))
       (steps (cdr parsed-file)))
  (format #t "names: ~a\nsteps: ~a\n" names steps)
  (define name-count (vector-length names))
  (for-each (lambda (s)
      (define head (vector-ref names 0))
      (define swap-pos (modulo s name-count))
      (vector-set! names 0 (vector-ref names swap-pos))
      (vector-set! names swap-pos head)
    ) steps)
  (format #t "P3: Chosen name: ~a\n" (vector-ref names 0))
)