6 ms·
im having a lot of fun using common lisp for aoc too. for fun, my approach is to only use lists and standard lib operations on them. i am really amazed at how e
by medo-bear 5y ago
im having a lot of fun using common lisp for aoc too. for fun, my approach is to only use lists and standard lib operations on them. i am really amazed at how elegant and powerful the loop, map*, and reduce operations are. one thing i found that i needed to be mindful of are the different quality operators [0].
[0] http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node74.html http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node74.html
- taeric 5y agoYeah, I'm not using any libraries. Hardest part, typically, is parsing the input in. Mainly because I don't know how. Found some fun dangerous ways that work for me
- Jtsummers 5y agoI just straight used `read` for several of the days. It worked very well, even if it lacked all safety checks you might normally want.
- taeric 5y agoYeah, that is the dangerous way. :) I actually really like it, oddly enough.
- Jtsummers 5y agoI think I used it for the bingo day, too. cl-ppcre for the first line (comma separated list of numbers) and then 5x5 loops calling read over and over to fill out the bingo cards. Why jump through parsing hoops when the language will do it for you? I've also been solving them in Ada. It's not as convenient as just read, but if you instantiate an IO package for a type you can do the same kind of thing. So I made an enumeration and an IO package: type Command is (Forward, Up, Down); package Direction_IO is new Enumeration_IO(Direction); use Direction_IO; Then reading each line was just: C: Command; D: Integer; Get(File, C); Get(File, D); Other than the setup (3 extra lines), it's as easy as the Lisp version to use.
- taeric 5y agoI also had fun for the long csv lines by making a temp readtable that set comma as whitespace and then just read the numbers in.
- na85 5y agoMAPCAR and UIOP:READ-FILE-LINES or READ-FILE-STRING will get you most of the way there.
- taeric 5y agoStandard (read stream nil nil) in a loop has been working rather well. I originally was just using read-line and then for char across line. That isn't hard. Just has been a significant portion of some solutions. Granted... The solution for some is a four line loop...
- DickieStarshine 5y agoI use this: (defun get-file (filename) (with-open-file (stream filename) (loop for line = (read-line stream nil) while line collect (parse-integer line))))
- taeric 5y agoI've so far had good mileage with basically the following: (with-input-from-string (stream "1,2,3") (let ((*readtable* (copy-readtable))) (set-syntax-from-char #\, #\ ) (loop for num = (read stream nil nil) while num collect num)))