You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.6 KiB
1.6 KiB
Solution to p6
First load the data as a list of cons cells (start . end)
(with-temp-buffer
(insert-file-contents "input")
(advent/replace-multiple-regex-buffer
'(
("^" . "(")
("$" . ")")
))
(goto-char (point-min))
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(eval-buffer))
This is for part 1. Quite straightforward
(-sum (-map #'eval (apply #'-zip-lists (-rotate 1 data))))
4412382293768
For part 2, we need a different approach. let's transpose the whole buffer
(with-temp-buffer
(insert-file-contents "input")
(goto-char (point-max))
(beginning-of-line)
(kill-line)
(backward-delete-char 1)
(goto-char (point-min))
(yank) (insert "\n")
(advent/replace-multiple-regex-buffer
'(
("^" . "\"")
("$" . "\"")
))
(goto-char (point-min))
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(eval-buffer)
(with-temp-buffer
(apply #'insert (--map (apply 'string it) (apply #'-zip-lists (-map #'advent/split-string-into-char-list data))))
(advent/replace-multiple-regex-buffer
'(("\\([*+]\\)" . ") (\\1 "))
)
(goto-char (point-max))
(insert ")))")
(goto-char (point-min))
(insert "(setq data2 '(")
(delete-char 1)
(eval-buffer)))
Then do the math
(-sum (-map #'eval data2))
7858808482092