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.4 KiB

Solution to p10

  (with-temp-buffer
    (insert-file-contents "input-test")
    (advent/replace-multiple-regex-buffer
     '(("," . " ")
       ("^" . "(")
       ("$" . ")")
       ("\\[" . "\"")
       ("\\]" . "\"")
       ("{" . "(")
       ("}" . ")")
       ))
    (goto-char (point-min))
    (insert "(setq data '(")
    (goto-char (point-max))
    (insert "))")
    (eval-buffer))
  (defun zero-one (n)
    (if (eq n ?#) 1 0))

  (setq cleanedup-data (--map (cons (-map #'zero-one (advent/split-string-into-char-list (car it))) (cdr it)) data))
(0 1 1 0) (3) (1 3) (2) (2 3) (0 2) (0 1) (3 5 4 7)
(0 0 0 1 0) (0 2 3 4) (2 3) (0 4) (0 1 2) (1 2 3 4) (7 5 12 7 2)
(0 1 1 1 0 1) (0 1 2 3 4) (0 3 4) (0 1 2 4 5) (1 2) (10 11 11 5 10 5)

for part 1 we do not need the last item

  (setq machines (--map (-drop-last 1 it) cleanedup-data))

  (defun init-machine (spec)
    (setq machine (-repeat (length (car spec)) 0)))

  (defun toggle (n)
    (logxor 0 1))

  (defun toggle-button (button)
    (setq machine (--map-indexed (if (-contains-p button it-index) (logxor it 1) it) machine)))

  (init-machine (car machines))

  (toggle-button '(1))