diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-11-06 09:58:38 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-11-06 09:58:38 -0800 |
commit | 4fd1aae518076adc8b97735225c678d6a362328d (patch) | |
tree | 97d61b659fc3cac628d0cdee71128a0baee2cb73 /2021/10/code.tl | |
download | advent-4fd1aae518076adc8b97735225c678d6a362328d.tar.gz advent-4fd1aae518076adc8b97735225c678d6a362328d.tar.bz2 advent-4fd1aae518076adc8b97735225c678d6a362328d.zip |
Kazinator's Advent of Code stuff.
Diffstat (limited to '2021/10/code.tl')
-rw-r--r-- | 2021/10/code.tl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/2021/10/code.tl b/2021/10/code.tl new file mode 100644 index 0000000..4e020cb --- /dev/null +++ b/2021/10/code.tl @@ -0,0 +1,35 @@ +(defun corrupt (str) + (if-match (@pos . @len) (search-str-tree str '("(]" "(}" "(>" + "[)" "[}" "[>" + "{)" "{]" "{>" + "<)" "<]" "<}")) + pos)) + +(defun reduxe (str) + (while-match (@pos . @len) (search-str-tree str '("()" "[]" "{}" "<>")) + (del [str pos..(ssucc pos)])) + str) + +(defun solve-part-one (: (name "input")) + (with-stream (s (open-file name)) + (let ((score 0)) + (whilet ((line (get-line s))) + (let ((rline (reduxe line))) + (iflet ((pos (corrupt rline))) + (inc score + (ecaseq [rline (succ pos)] + (#\) 3) + (#\] 57) + (#\} 1197) + (#\> 25137)))))) + score))) + +(defun solve-part-two (: (name "input")) + (flow + (file-get-lines name) + (mapcar reduxe) + (remove-if [orf corrupt empty]) + (mapcar (opip (mapcar (relate "([{<" #(1 2 3 4))) + (rpoly 5))) + (sort) + [callf ref use [chain len (lop trunc 2)]])) |