aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/02
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/02')
-rw-r--r--AoC2022/02/solver.el30
1 files changed, 12 insertions, 18 deletions
diff --git a/AoC2022/02/solver.el b/AoC2022/02/solver.el
index 0bb92d2..9a1d68b 100644
--- a/AoC2022/02/solver.el
+++ b/AoC2022/02/solver.el
@@ -60,28 +60,22 @@
('win (car (rassq b solver-results)))))
;; 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))))
+
+(defun solver-fixed-plays (_oponent my-game)
+ (solver-translate my-game))
(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))))
+ (solver-strategy-a (solver-translate-strategy my-game) oponent))
-(defun solver-parse ()
+(defun solver-parse (strategy)
(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))))
+ (seq-reduce (lambda (acc game)
+ (let* ((oponent (solver-translate (aref game 0)))
+ (my-game (funcall strategy oponent (aref game 2))))
+ (+ 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))))))
+ (should (= 12535 (solver-parse #'solver-fixed-plays)))
+ (should (= 15457 (solver-parse #'solver-reactive-plays))))