I’m a “Neovim Refugee” trying to get a deeper/better understanding of how emacs lisp works and how i can use it to expand on my emacs setup. I have never done anything in lisp before and still struggle to understand how single quotes signify a function or what ever.

With that said, i was also planning on doing AoC this year. Originally i wanted to look into zig or go, but now think that this might be the opportunity to dive into lisp for a bit.

But with knowing basically nothing: Is this even “viable”, or advisable? Should i be looking at common lisp instead? Or would you say that’s a pretty dumb idea and i should rather learn it in a different way?

  • Piotr_Klibert@alien.topB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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 :)