aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-01-12 02:13:13 +0100
committerOscar Najera <hi@oscarnajera.com>2023-01-12 02:13:13 +0100
commit274fd4e1d80e8a10fd5cc73c50b07add44b4964b (patch)
tree321620217544489b4342b2fd282e20ca13ed376f
parenta5ae3ed934ca1f283a4cc9b93f6ae10d942db909 (diff)
downloadscratch-274fd4e1d80e8a10fd5cc73c50b07add44b4964b.tar.gz
scratch-274fd4e1d80e8a10fd5cc73c50b07add44b4964b.tar.bz2
scratch-274fd4e1d80e8a10fd5cc73c50b07add44b4964b.zip
Not working
Test the comparison of states
-rw-r--r--AoC2022/19/solver.lisp82
1 files 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)