aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/02/input
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/02/input')
0 files changed, 0 insertions, 0 deletions
2C3B41 } .highlight { background: #263238; color: #EEFFFF } .highlight .c { color: #546E7A; font-style: italic } /* Comment */ .highlight .err { color: #FF5370 } /* Error */ .highlight .esc { color: #89DDFF } /* Escape */ .highlight .g { color: #EEFFFF } /* Generic */ .highlight .k { color: #BB80B3 } /* Keyword */ .highlight .l { color: #C3E88D } /* Literal */ .highlight .n { color: #EEFFFF } /* Name */ .highlight .o { color: #89DDFF } /* Operator */ .highlight .p { color: #89DDFF } /* Punctuation */ .highlight .ch { color: #546E7A; font-style: italic } /* Comment.Hashbang */ .highlight .cm { color: #546E7A; font-style: italic } /* Comment.Multiline */ .highlight .cp { color: #546E7A; font-style: italic } /* Comment.Preproc */ .highlight .cpf { color: #546E7A; font-style: italic } /* Comment.PreprocFile */ .highlight .c1 { color: #546E7A; font-style: italic } /* Comment.Single */ .highlight .cs { color: #546E7A; font-style: italic } /* Comment.Special */ .highlight .gd { color: #FF5370 } /* Generic.Deleted */ .highlight .ge { color: #89DDFF } /* Generic.Emph */ .highlight .ges { color: #FFCB6B } /* Generic.EmphStrong */ .highlight .gr { color: #FF5370 } /* Generic.Error */ .highlight .gh { color: #C3E88D } /* Generic.Heading */ .highlight .gi { color: #C3E88D } /* Generic.Inserted */ .highlight .go { color: #546E7A } /* Generic.Output */ .highlight .gp { color: #FFCB6B } /* Generic.Prompt */ .highlight .gs { color: #FF5370 } /* Generic.Strong */ .highlight .gu { color: #89DDFF } /* Generic.Subheading */ .highlight .gt { color: #FF5370 } /* Generic.Traceback */ .highlight .kc { color: #89DDFF } /* Keyword.Constant */ .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!))))

(fiveam:run-all-tests)