cleaning up a bit before solving 2018/07 part 1
This commit is contained in:
parent
14b3da7893
commit
f3ceb796b6
4 changed files with 17 additions and 61 deletions
|
@ -1,4 +0,0 @@
|
||||||
;;; Directory Local Variables -*- no-byte-compile: t -*-
|
|
||||||
;;; For more information see (info "(emacs) Directory Variables")
|
|
||||||
|
|
||||||
((lisp-mode . ((inferior-lisp-program . "sbcl"))))
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@
|
||||||
*.x86f
|
*.x86f
|
||||||
*~
|
*~
|
||||||
.#*
|
.#*
|
||||||
|
*.~undo-tree~
|
|
@ -37,64 +37,14 @@ Step F must be finished before step E can begin."))
|
||||||
if (not (member p produced))
|
if (not (member p produced))
|
||||||
collect p))))
|
collect p))))
|
||||||
|
|
||||||
(defun dependency-lessp (a b)
|
|
||||||
(string-lessp (second a) (second b)))
|
|
||||||
|
|
||||||
(defun next-ready-rules (dependencies done)
|
|
||||||
(let ((available (append done (steps-without-dependencies dependencies))))
|
|
||||||
(sort
|
|
||||||
(loop for d in dependencies
|
|
||||||
if (member (first d) available)
|
|
||||||
if (not (member (second d) available))
|
|
||||||
if (prerequisites-availablep available (second d) dependencies)
|
|
||||||
collect d)
|
|
||||||
#'dependency-lessp)))
|
|
||||||
|
|
||||||
|
|
||||||
(defun merge-steps (steps rule)
|
|
||||||
(if (member (first rule) steps)
|
|
||||||
(append steps (list (second rule)))
|
|
||||||
(append steps rule)))
|
|
||||||
|
|
||||||
(defun number-steps (dependencies)
|
|
||||||
(length
|
|
||||||
(remove-duplicates
|
|
||||||
(append
|
|
||||||
(map 'list #'first dependencies)
|
|
||||||
(map 'list #'second dependencies)))))
|
|
||||||
|
|
||||||
(defparameter *counter* 0)
|
|
||||||
(setf *counter* 0)
|
|
||||||
|
|
||||||
(defparameter *path* '())
|
|
||||||
|
|
||||||
(defun assy-order (dependencies)
|
|
||||||
(let ((todo (queues:make-queue :simple-queue))
|
|
||||||
(target-length (number-steps dependencies))
|
|
||||||
(path '()))
|
|
||||||
(loop for step in (steps-without-dependencies dependencies)
|
|
||||||
do (queues:qpush todo (list step)))
|
|
||||||
(queues:print-queue todo)
|
|
||||||
(loop
|
|
||||||
do (setf path (queues:qpop todo))
|
|
||||||
do (setf *path* path)
|
|
||||||
do (incf *counter*)
|
|
||||||
while (and path (not (= target-length (length path))))
|
|
||||||
do (loop
|
|
||||||
for rule in (next-ready-rules dependencies path)
|
|
||||||
for tgt = (second rule)
|
|
||||||
for npath = (append path (list tgt))
|
|
||||||
do (queues:qpush todo npath)))
|
|
||||||
path))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun print-thread-info ()
|
|
||||||
(let* ((curr-thread sb-thread:*current-thread*)
|
|
||||||
(curr-thread-name (sb-thread:thread-name curr-thread))
|
|
||||||
(all-threads (sb-thread:list-all-threads)))
|
|
||||||
(format t "Current thread: ~a~%~%" curr-thread)
|
|
||||||
(format t "Current thread name: ~a~%~%" curr-thread-name)
|
|
||||||
(format t "All threads:~% ~{~a~%~}~%" all-threads))
|
|
||||||
nil)
|
|
||||||
|
|
|
@ -61,3 +61,12 @@
|
||||||
(if val
|
(if val
|
||||||
val
|
val
|
||||||
(setf (gethash key *input-data-cache*) (fetch-input-data year day)))))
|
(setf (gethash key *input-data-cache*) (fetch-input-data year day)))))
|
||||||
|
|
||||||
|
(defun print-thread-info ()
|
||||||
|
(let* ((curr-thread sb-thread:*current-thread*)
|
||||||
|
(curr-thread-name (sb-thread:thread-name curr-thread))
|
||||||
|
(all-threads (sb-thread:list-all-threads)))
|
||||||
|
(format t "Current thread: ~a~%~%" curr-thread)
|
||||||
|
(format t "Current thread name: ~a~%~%" curr-thread-name)
|
||||||
|
(format t "All threads:~% ~{~a~%~}~%" all-threads))
|
||||||
|
nil)
|
||||||
|
|
Loading…
Reference in a new issue