aboutsummaryrefslogtreecommitdiff
path: root/puzzle-2.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-06-26 08:35:43 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-06-26 08:36:53 +0100
commitc0964cbb42710129a217e84bf7525f68f3fd670e (patch)
treefaa7e762fb747342c44c9852eee84ec7e3f2860a /puzzle-2.lisp
parent29cacf2394a6d64f1ab3d5ba13a35f3beb08c3c7 (diff)
downloadadvent-of-code-c0964cbb42710129a217e84bf7525f68f3fd670e.tar.gz
advent-of-code-c0964cbb42710129a217e84bf7525f68f3fd670e.tar.bz2
advent-of-code-c0964cbb42710129a217e84bf7525f68f3fd670e.zip
(*->2022)~made it clear what advent of code I'm doing
Diffstat (limited to 'puzzle-2.lisp')
-rw-r--r--puzzle-2.lisp54
1 files changed, 0 insertions, 54 deletions
diff --git a/puzzle-2.lisp b/puzzle-2.lisp
deleted file mode 100644
index 377b6ba..0000000
--- a/puzzle-2.lisp
+++ /dev/null
@@ -1,54 +0,0 @@
-(defvar input (uiop:read-file-string "puzzle-2-input.txt"))
-;; Each newline represents a new round, which we should parse on the go
-
-(defun sensible-convert-input (str)
- (cond
- ((or (string= str "X") (string= str "A")) 0)
- ((or (string= str "Y") (string= str "B")) 1)
- ((or (string= str "Z") (string= str "C")) 2)))
-
-;; Round 1
-(defvar rounds
- (with-input-from-string (stream input)
- (loop
- for strategy = (read-line stream nil)
- until (null strategy)
- collect
- (let ((opponent (subseq strategy 0 1))
- (yours (subseq strategy 2 3)))
- (list (sensible-convert-input opponent) (sensible-convert-input yours))))))
-
-(loop
- for round in rounds
- until (null round)
- sum
- (destructuring-bind (opp you) round
- (+
- 1 you ;; base score
- (cond ; outcome score
- ((eq you opp) 3)
- ((eq (mod (+ 1 opp) 3) you) 6)
- (t 0)))))
-
-;; Round 2.
-
-;; We can still use the same rounds data as previously, just
-;; reinterpret it in when doing the sum.
-
-(defun get-correct-choice (opponent outcome)
- (case outcome
- (0 (mod (- opponent 1) 3))
- (1 opp)
- (2 (mod (+ 1 opponent) 3))
- (t 0)))
-
-(loop for round in rounds
- sum
- (destructuring-bind (opp you) round
- (let ((choice (get-correct-choice opp you)))
- (+ 1 choice
- (case you ;; outcome -> score
- (0 0)
- (1 3)
- (2 6)
- (t 0))))))