diff options
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)]])) |