aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/09/input
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2022-12-17 20:21:04 +0100
committerOscar Najera <hi@oscarnajera.com>2022-12-17 20:21:04 +0100
commit9b40049d0841b9caa5712d54e6c71c6c9fbf67ab (patch)
tree3790c868ecbb158100f6137d6a7461b9e18b9c79 /AoC2022/09/input
parentea80ec7f238cb5f3930800ccfbc9920436bc8189 (diff)
downloadscratch-9b40049d0841b9caa5712d54e6c71c6c9fbf67ab.tar.gz
scratch-9b40049d0841b9caa5712d54e6c71c6c9fbf67ab.tar.bz2
scratch-9b40049d0841b9caa5712d54e6c71c6c9fbf67ab.zip
organizing
Diffstat (limited to 'AoC2022/09/input')
0 files changed, 0 insertions, 0 deletions
ant */ .highlight .kd { color: #BB80B3 } /* Keyword.Declaration */ .highlight .kn { color: #89DDFF; font-style: italic } /* Keyword.Namespace */ .highlight .kp { color: #89DDFF } /* Keyword.Pseudo */ .highlight .kr { color: #BB80B3 } /* Keyword.Reserved */ .highlight .kt { color: #BB80B3 } /* Keyword.Type */ .highlight .ld { color: #C3E88D } /* Literal.Date */ .highlight .m { color: #F78C6C } /* Literal.Number */ .highlight .s { color: #C3E88D } /* Literal.String */ .highlight .na { color: #BB80B3 } /* Name.Attribute */ .highlight .nb { color: #82AAFF } /* Name.Builtin */ .highlight .nc { color: #FFCB6B } /* Name.Class */ .highlight .no { color: #EEFFFF } /* Name.Constant */ .highlight .nd { color: #82AAFF } /* Name.Decorator */ .highlight .ni { color: #89DDFF } /* Name.Entity */ .highlight .ne { color: #FFCB6B } /* Name.Exception */ .highlight .nf { color: #82AAFF } /* Name.Function */ .highlight .nl { color: #82AAFF } /* Name.Label */ .highlight .nn { color: #FFCB6B } /* Name.Namespace */ .highlight .nx { color: #EEFFFF } /* Name.Other */ .highlight .py { color: #FFCB6B } /* Name.Property */ .highlight .nt { color: #FF5370 } /* Name.Tag */ .highlight .nv { color: #89DDFF } /* Name.Variable */ .highlight .ow { color: #89DDFF; font-style: italic } /* Operator.Word */ .highlight .pm { color: #89DDFF } /* Punctuation.Marker */ .highlight .w { color: #EEFFFF } /* Text.Whitespace */ .highlight .mb { color: #F78C6C } /* Literal.Number.Bin */ .highlight .mf { color: #F78C6C } /* Literal.Number.Float */ .highlight .mh { color: #F78C6C } /* Literal.Number.Hex */ .highlight .mi { color: #F78C6C } /* Literal.Number.Integer */ .highlight .mo { color: #F78C6C } /* Literal.Number.Oct */ .highlight .sa { color: #BB80B3 } /* Literal.String.Affix */ .highlight .sb { color: #C3E88D } /* Literal.String.Backtick */ .highlight .sc { color: #C3E88D } /* Literal.String.Char */ .highlight .dl { color: #EEFFFF } /* Literal.String.Delimiter */ .highlight .sd { color: #546E7A; font-style: italic } /* Literal.String.Doc */ .highlight .s2 { color: #C3E88D } /* Literal.String.Double */ .highlight .se { color: #EEFFFF } /* Literal.String.Escape */ .highlight .sh { color: #C3E88D } /* Literal.String.Heredoc */ .highlight .si { color: #89DDFF } /* Literal.String.Interpol */ .highlight .sx { color: #C3E88D } /* Literal.String.Other */ .highlight .sr { color: #89DDFF } /* Literal.String.Regex */ .highlight .s1 { color: #C3E88D } /* Literal.String.Single */ .highlight .ss { color: #89DDFF } /* Literal.String.Symbol */ .highlight .bp { color: #89DDFF } /* Name.Builtin.Pseudo */ .highlight .fm { color: #82AAFF } /* Name.Function.Magic */ .highlight .vc { color: #89DDFF } /* Name.Variable.Class */ .highlight .vg { color: #89DDFF } /* Name.Variable.Global */ .highlight .vi { color: #89DDFF } /* Name.Variable.Instance */ .highlight .vm { color: #82AAFF } /* Name.Variable.Magic */ .highlight .il { color: #F78C6C } /* Literal.Number.Integer.Long */
;; this one abuses the file format and white space

(ql:quickload :fiveam)

(defun build-stacks (in)
  (let* ((input (read-line in))
         (stack-amount (ceiling (/ (length input) 4)))
         (stacks (make-array stack-amount :initial-element nil)))
    (loop for dock = input then (read-line in)
          while (not  (eq (aref dock 1) #\1))
          do (loop
               for idx from 0 below stack-amount
               for entry = (aref dock (+ 1 (* 4 idx)))
               unless (eq entry #\ ) do (push entry (aref stacks idx))))
    (map 'vector #'nreverse stacks)))

(defun single-move! (stacks amount from to)
  (dotimes (_ amount)
    (push (pop (aref stacks from)) (aref stacks to))))

(defun bulk-move! (stacks amount from to)
  (setf (aref stacks to)
        (append (subseq (aref stacks from) 0 amount)
                (aref stacks to)))
  (setf (aref stacks from) (subseq (aref stacks from) amount)))

(defun apply-moves (execution in stacks)
  (loop for action = (read in nil nil)
        while action
        do (let ((amount (read in nil nil))
                 (from (progn (read in nil nil) (1- (read in nil nil))))
                 (to (progn (read in nil nil) (1- (read in nil nil)))))
             (funcall execution stacks amount from to)))
  stacks)

(defun solver (execution)
  (with-open-file (in "input")
    (map 'string #'car
         (apply-moves execution in
                      (build-stacks in)))))


(fiveam:test results
  (fiveam:is (equal "TPGVQPFDH" (solver #'single-move!)))
  (fiveam:is (equal "DMRDFRHHH" (solver #'bulk-move!))))