aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/makefile
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-12-03 18:11:24 +0100
committerOscar Najera <hi@oscarnajera.com>2023-12-03 18:11:24 +0100
commit1c147396427dbd05abadb4c1bbf9a60bb49770ec (patch)
tree37b50feeffe88ac241ca48001b19e7b267103ccc /AoC2022/makefile
parentb67dd423cd43b056c19838144e39963d3ba02fb0 (diff)
downloadscratch-1c147396427dbd05abadb4c1bbf9a60bb49770ec.tar.gz
scratch-1c147396427dbd05abadb4c1bbf9a60bb49770ec.tar.bz2
scratch-1c147396427dbd05abadb4c1bbf9a60bb49770ec.zip
[AoC2023] day01 lisp fail 2nd
Diffstat (limited to 'AoC2022/makefile')
0 files changed, 0 insertions, 0 deletions
ric.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 */
(ql:quickload :fiveam)

(defconstant results '((rock . scissors) (scissors . paper) (paper . rock))
  "Win-lose pairs")

(defun translate (play)
  (case play
    ((A X) 'rock)
    ((B Y) 'paper)
    ((C Z) 'scissors)))

(defun weight (play)
  (case play
    (rock 1)
    (paper 2)
    (scissors 3)))

(defun match (my other)
  (cond
    ((eq my other) (values 3 'draw))
    ((eq other (cdr (assoc my results))) (values 6 'win))
    (t (values 0 'loose))))

(defun strategy (play)
  (ecase play
      (X 'loose)
      (Y 'draw)
      (Z 'win)))

(defun pick-move (strategy other)
  (ecase strategy
    (loose (cdr (assoc other results)))
    (draw other)
    (win (car (rassoc other results)))))

(defun fixed-plays (oponent my)
  (declare (ignore oponent))
  (translate my))

(defun reactive-plays (oponent my)
  (pick-move (strategy my) oponent))

(defun solver (strategy)
  (with-open-file (in "input")
    (loop :for n :from 0
          :for op = (translate (read in nil nil))
          :while op
          :for my = (funcall strategy op (read in nil nil))
          :sum (+ (weight my) (match my op)))))

(fiveam:test results
  (fiveam:is (= 12535 (solver #'fixed-plays)))
  (fiveam:is (= 15457 (solver #'reactive-plays))))