this post was submitted on 09 Nov 2025
6 points (80.0% 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 3: The Deepest Fit

  • 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/

Also, don't wait for me to make these posts, feel free to post yourself :)

you are viewing a single comment's thread
view the rest of the comments
[โ€“] vole@lemmy.world 3 points 1 month ago* (last edited 1 month ago) (2 children)

Scheme/Guile

Guile doesn't seem to come with a bag implementation :(. Not a big deal, a linear scan works about as well.

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

(define (parse-file file-name)
  (let* ((p (open-input-file file-name))
        (comma-split (string-split (read-line p) #\,))
        (number-list (map string->number comma-split)))
    number-list))

(let* ((crates (parse-file "notes/everybody_codes_e2025_q03_p1.txt"))
       (dedup-crates (delete-duplicates crates)))
  (format #t "P1 Answer: ~a\n\n" (apply + dedup-crates)))


(let* ((crates (parse-file "notes/everybody_codes_e2025_q03_p2.txt"))
       (dedup-crates (delete-duplicates crates))
       (sorted-crates (sort dedup-crates <)))
  (format #t "P2 Answer: ~a\n\n" (apply + (take sorted-crates 20))))


(let* ((crates (parse-file "notes/everybody_codes_e2025_q03_p3.txt"))
       (sorted-crates (sort crates <))
       (largest-set-size (let loop ((count 0) (l sorted-crates) (c #f) (max-count 0))
         (if (nil? l)
             max-count
             (let* ((new-c (car l))
                    (new-count (if (equal? new-c c) (+ count 1) 1)))
               (loop new-count (cdr l) new-c (max new-count max-count)))))))
  (format #t "P3 Answer: ~a\n\n" largest-set-size))
[โ€“] ragingHungryPanda@piefed.keyboardvagabond.com 1 points 3 weeks ago (1 children)

I'm so far behind on these, but it's rare that I see a lanugage I've never heard before. I've heard of scheme. How did you come to using this language for the challenges?

[โ€“] vole@lemmy.world 2 points 3 weeks ago

I wanted to learn scheme and perhaps work through SICP. Guille seemed like a reasonable scheme to choose because I've also been considering learning Guix. Guix is a package manager similar to Nix, and it uses Guille as its configuration language.