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.3 KiB
1.3 KiB
Solution to p1
First load the data as a list of positive or negative numbers
(with-temp-buffer
(insert-file-contents "input")
(advent/replace-multiple-regex-buffer
'(("L" . "-")
("R" . "")))
(goto-char (point-min))
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(eval-buffer))
Then add the rotations starting from the initial offset and count the number of 0's mod 100; that is what we need for part 1
(length (--filter (= 0 it)
(--map (mod it 100)
(-running-sum (cons 50 data)))))
962
For part 2, This works:
- we count the number of full turns that have been done in each rotation. Since there are corner cases we need to average over two offsets of ½
(defun advent/consecutive-pairs (list)
(-zip-pair list (cdr list)))
(defun average (li)
(/ (-sum li) (length li)))
(let ((number-lists (--map (-running-sum (cons it data))
(list 50.5 49.5))))
(average (--map
(-sum (--map (abs (- (car it) (cdr it)))
(advent/consecutive-pairs
(--map (floor it 100) it))))
number-lists)))
5782