aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/02
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/02')
-rw-r--r--AoC2022/02/solver.el45
1 files changed, 24 insertions, 21 deletions
diff --git a/AoC2022/02/solver.el b/AoC2022/02/solver.el
index 573a2d4..0bb92d2 100644
--- a/AoC2022/02/solver.el
+++ b/AoC2022/02/solver.el
@@ -22,6 +22,7 @@
(require 'seq)
(require 'ert)
;; play to order
+
(defun solver-translate (play)
(pcase play
((or ?A ?X) 'rock)
@@ -58,27 +59,29 @@
('draw b)
('win (car (rassq b solver-results)))))
-(solver-strategy-a 'win 'rock)
+;; uni
+(defun solver-fixed-plays (oponent my-game)
+ (let ((my-game (solver-translate my-game)))
+ (+ (solver-weight my-game) (solver-result-a my-game oponent))))
-(should (= 12535
- (with-temp-buffer
- (insert-file-contents "input")
- (seq-reduce
- (lambda (acc game)
- (let ((oponent (solver-translate (aref game 0)))
- (my-game (solver-translate (aref game 2))))
- (+ acc (solver-weight my-game) (solver-result-a my-game oponent))))
- (split-string (buffer-string) "\n" t)
- 0))))
+(defun solver-reactive-plays (oponent my-game)
+ (let ((my-game (solver-strategy-a (solver-translate-strategy my-game) oponent)))
+ (+ (solver-weight my-game) (solver-result-a my-game oponent))))
-(with-temp-buffer
- (insert-file-contents "input")
- (seq-reduce
- (lambda (acc game)
- (let* ((oponent (solver-translate (aref game 0)))
- (my-strategy (solver-translate-strategy (aref game 2)))
- (my-game (solver-strategy-a my-strategy oponent)))
+(defun solver-parse ()
+ (with-temp-buffer
+ (insert-file-contents "input")
+ (mapcar (lambda (game)
+ (cons (solver-translate (aref game 0)) (aref game 2)))
+ (split-string (buffer-string) "\n" t))))
- (+ acc (solver-weight my-game) (solver-result-a my-game oponent))))
- (split-string (buffer-string) "\n" t)
- 0))
+(ert-deftest solver-results ()
+ (let ((games (solver-parse)))
+ (should (= 12535
+ (apply #'+ (mapcar (lambda (game)
+ (solver-fixed-plays (car game) (cdr game)))
+ games))))
+ (should (= 15457
+ (apply #'+ (mapcar (lambda (game)
+ (solver-reactive-plays (car game) (cdr game)))
+ games))))))