From 274fd4e1d80e8a10fd5cc73c50b07add44b4964b Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Thu, 12 Jan 2023 02:13:13 +0100 Subject: Not working Test the comparison of states --- AoC2022/19/solver.lisp | 82 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/AoC2022/19/solver.lisp b/AoC2022/19/solver.lisp index 7617628..b939bea 100644 --- a/AoC2022/19/solver.lisp +++ b/AoC2022/19/solver.lisp @@ -1,7 +1,7 @@ -(ql:quickload '(fiveam uiop cl-ppcre fset lparallel)) +(ql:quickload '(fiveam uiop cl-ppcre fset lparallel arrows)) ;; (setf lparallel:*kernel* (lparallel:make-kernel 8)) -(declaim (optimize (speed 0) (space 0) (debug 3))) +;; (declaim (optimize (speed 0) (space 0) (debug 3))) (defun material (string) (cond @@ -48,9 +48,6 @@ (material-collect robots resources) blueprints (1- time-left)))))) - (if (zerop time-left) - (values robots resources time-left)) - (defun next-step2 (build-next robots resources blueprints) (let ((req (bot-requirements build-next blueprints))) (when (can-build-robot-pm req resources) @@ -58,22 +55,6 @@ (resources-left (consume req resources))) (values new-robots (material-collect robots resources-left)))))) - -(let ((factory (cdar (get-blueprints "/home/titan/dev/scratch/AoC2022/19/eg-in")))) - ;; (next-step2 :clay (fset:bag :ore) (fset:bag :ore :ore) factory) - ;; (probe2 (list (fset:bag :ore :clay) (fset:bag :ore :ore)) factory) - ;; (arrows:-> - ;; (list (list (fset:bag :ore :clay) (fset:bag :ore :ore))) - ;; (advance factory) - ;; (advance factory) - ;; (advance factory) - ;; (advance factory) - ;; (advance factory) - ;; (advance factory) - ;; (advance factory) - ;; ) - (find-best (list (list (fset:bag :ore) (fset:bag))) factory 9)) - (defun probe2 (current-state blueprints) (destructuring-bind (robots resources) current-state (reduce @@ -96,6 +77,31 @@ robot-resource-list :initial-value nil)) +(resource-increase + (list (fset:bag :obsidian :ore) (fset:bag :clay)) 2) + +(defun materials< (m1 m2) + (eq :less + (fset:reduce (lambda (result material) + (if (eq result :equal) + (let ((c1 (fset:multiplicity m1 material)) + (c2 (fset:multiplicity m2 material))) + (cond + ((< c1 c2) :less) + ((= c1 c2) :equal) + ((> c1 c2) :greater))) + result)) + '(:geode :obsidian :clay :ore) + :initial-value :equal))) + +(materials< (fset:bag :clay) (fset:bag :obsidian :ore)) + +(defun resource-increase (current-state time-left) + (destructuring-bind (robots resources) current-state + (loop for s = resources then (fset:bag-sum s robots) + repeat time-left + finally (return s)))) + (defun find-best (robot-resource-list blueprints time-left) (if (zerop time-left) robot-resource-list @@ -158,6 +164,26 @@ (probe (fset:bag :ore) (fset:empty-bag) recipes time-left))) blueprints)) +(let ((factory (cdar (get-blueprints "/home/titan/dev/scratch/AoC2022/19/eg-in")))) + ;; (next-step2 :clay (fset:bag :ore) (fset:bag :ore :ore) factory) + ;; (probe2 (list (fset:bag :ore :clay) (fset:bag :ore :ore)) factory) + ;; (arrows:-> + ;; (list (list (fset:bag :ore :clay) (fset:bag :ore :ore))) + ;; (advance factory) + ;; (advance factory) + ;; (advance factory) + ;; (advance factory) + ;; (advance factory) + ;; (advance factory) + ;; (advance factory) + ;; ) + (sort + ;; (mapcar (lambda (state) + ;; (fset:multiplicity (cadr state) :ore))) + (find-best (list (list (fset:bag :ore) (fset:bag))) factory 5) + #'materials< :key (lambda (state) (resource-increase state 5)))) + + ;; (require :sb-sprof) ;; (progn ;; (sb-sprof:start-profiling) @@ -166,16 +192,16 @@ ;; (sb-sprof:stop-profiling) ;; (sb-sprof:report)) -(step - (probe (fset:bag :ore) (fset:empty-bag) (cdar (get-blueprints "/home/titan/dev/scratch/AoC2022/19/eg-in")) 22)) +;; (step +;; (probe (fset:bag :ore) (fset:empty-bag) (cdar (get-blueprints "/home/titan/dev/scratch/AoC2022/19/eg-in")) 22)) -(fiveam:test solution - ;; part1 - ;; (fiveam:is (= 33 (solver (get-blueprints "eg-in") 24))) - (fiveam:is (= 1266 (solver (get-blueprints "/home/titan/dev/scratch/AoC2022/19/input") 24))) - ) +;; (fiveam:test solution +;; ;; part1 +;; ;; (fiveam:is (= 33 (solver (get-blueprints "eg-in") 24))) +;; (fiveam:is (= 1266 (solver (get-blueprints "/home/titan/dev/scratch/AoC2022/19/input") 24))) +;; ) ;; (let ((blueprints ;; ;; (cdadr) -- cgit v1.2.3