• 0 Posts
  • 2 Comments
Joined 10 months ago
cake
Cake day: November 25th, 2023

help-circle
  • You could have just tried any of previous years of AOC. Just go to their webpage and start doing them.

    I did just that, to see how “viable” Elisp would be. I solved this: https://adventofcode.com/2022/day/1

    with:

    (cl-labels
        ((split-to-numbers (lst)
           (--map (->> (s-split "\n" it) (-map #'string-to-number)) lst)))
      (skip-chars-forward " \t\n")
      (let* ((input (buffer-substring-no-properties (point) (point-max)))
             (subs (->> input s-trim (s-split "\n\n") split-to-numbers))
             (sorted (cl-sort (-map #'-sum subs) #'>)))
        (message "Winner: %s" (car sorted))))
    

    and then with:

    (save-excursion
      (calc-pop (calc-stack-size))
      (while (progn (skip-chars-forward " \t\n") (not (eobp)))
        (save-selected-window
          (calc-grab-region (point) (progn (forward-paragraph) (point)) nil)
          (calc-eval "VR+" 'macro)))
      (calc-pack (calc-stack-size))
      (calc-vector-max nil)
      (calc-top-n 1))
    

    which turned out to be ~1000 times slower, but also worked.

    So u/domsch1988, it’s demonstrably doable in Elisp :)