parent
50e2a39a2a
commit
d8551d7c06
@ 0,0 +1,7 @@


Step C must be finished before step A can begin.


Step C must be finished before step F can begin.


Step A must be finished before step B can begin.


Step A must be finished before step D can begin.


Step B must be finished before step E can begin.


Step D must be finished before step E can begin.


Step F must be finished before step E can begin.

@ 0,0 +1,47 @@


#lang debug br


(require graph)




#


Track the progress through the steps with a dag,


but track the state of the prerequisites with another dag (in the reverse direction)


#




(define dag (directedgraph null))


(define prereqs (weightedgraph/directed null))


(for ([ln (inlines (openinputfile "07.txt"))])


(matchdefine (list left right) (regexpmatch* #rx"(?<=[Ss]tep )." ln))


(adddirectededge! dag left right)


(adddirectededge! prereqs right left +inf.0))




(define (activateprereq! v1 v2)


;; a prereq is "met" if the edge weight is zero


(adddirectededge! prereqs v2 v1 0))




(define (prereqsmet? v)


;; check if all v's edges in the prereq graph are zero


(andmap zero? (map (λ (n) (edgeweight prereqs v n)) (getneighbors prereqs v))))




(define (findavailable g)


(filter prereqsmet? (getvertices g)))




(define (★)


(let loop ([vsavailable (findavailable prereqs)] [visited null])


(cond


[(= (length visited) (length (getvertices dag)))


(apply stringappend (reverse visited))]


[else


(match (sort vsavailable string<?)


[(list thisv others ...)


(foreach (λ (n) (activateprereq! thisv n)) (getneighbors dag thisv))


(define thisvisited (cons thisv visited))


(loop (filternot (λ (v) (member v thisvisited)) (findavailable prereqs))


thisvisited)])])))




#;(define (★★)


)


#;(★★)




(module+ test


(require rackunit)


(checkequal? (time (★)) "GNJOCHKSWTFMXLYDZABIREPVUQ")


#;(checkequal? (time (★★)) 566))

@ 0,0 +1,101 @@


Step O must be finished before step C can begin.


Step Y must be finished before step D can begin.


Step N must be finished before step D can begin.


Step G must be finished before step F can begin.


Step C must be finished before step Z can begin.


Step H must be finished before step K can begin.


Step W must be finished before step T can begin.


Step T must be finished before step F can begin.


Step S must be finished before step I can begin.


Step X must be finished before step B can begin.


Step J must be finished before step A can begin.


Step K must be finished before step D can begin.


Step Z must be finished before step A can begin.


Step A must be finished before step B can begin.


Step L must be finished before step V can begin.


Step F must be finished before step M can begin.


Step B must be finished before step V can begin.


Step M must be finished before step Q can begin.


Step D must be finished before step E can begin.


Step I must be finished before step U can begin.


Step R must be finished before step V can begin.


Step E must be finished before step U can begin.


Step P must be finished before step V can begin.


Step V must be finished before step Q can begin.


Step U must be finished before step Q can begin.


Step P must be finished before step U can begin.


Step O must be finished before step F can begin.


Step T must be finished before step M can begin.


Step I must be finished before step Q can begin.


Step M must be finished before step U can begin.


Step R must be finished before step E can begin.


Step T must be finished before step R can begin.


Step H must be finished before step S can begin.


Step L must be finished before step B can begin.


Step S must be finished before step Q can begin.


Step E must be finished before step Q can begin.


Step B must be finished before step Q can begin.


Step S must be finished before step M can begin.


Step C must be finished before step D can begin.


Step S must be finished before step R can begin.


Step G must be finished before step D can begin.


Step T must be finished before step E can begin.


Step T must be finished before step Q can begin.


Step N must be finished before step I can begin.


Step S must be finished before step P can begin.


Step N must be finished before step J can begin.


Step X must be finished before step L can begin.


Step G must be finished before step K can begin.


Step N must be finished before step E can begin.


Step H must be finished before step D can begin.


Step H must be finished before step P can begin.


Step O must be finished before step A can begin.


Step V must be finished before step U can begin.


Step F must be finished before step D can begin.


Step B must be finished before step P can begin.


Step T must be finished before step L can begin.


Step I must be finished before step P can begin.


Step K must be finished before step Z can begin.


Step G must be finished before step M can begin.


Step F must be finished before step Q can begin.


Step J must be finished before step L can begin.


Step H must be finished before step Q can begin.


Step W must be finished before step R can begin.


Step R must be finished before step U can begin.


Step P must be finished before step Q can begin.


Step D must be finished before step V can begin.


Step G must be finished before step C can begin.


Step Z must be finished before step B can begin.


Step O must be finished before step H can begin.


Step S must be finished before step A can begin.


Step J must be finished before step Q can begin.


Step N must be finished before step F can begin.


Step L must be finished before step R can begin.


Step O must be finished before step R can begin.


Step W must be finished before step M can begin.


Step J must be finished before step F can begin.


Step G must be finished before step W can begin.


Step K must be finished before step U can begin.


Step D must be finished before step U can begin.


Step W must be finished before step I can begin.


Step E must be finished before step V can begin.


Step Y must be finished before step Q can begin.


Step L must be finished before step E can begin.


Step S must be finished before step B can begin.


Step T must be finished before step V can begin.


Step C must be finished before step U can begin.


Step M must be finished before step P can begin.


Step G must be finished before step S can begin.


Step B must be finished before step R can begin.


Step K must be finished before step M can begin.


Step X must be finished before step A can begin.


Step R must be finished before step P can begin.


Step B must be finished before step I can begin.


Step C must be finished before step X can begin.


Step O must be finished before step P can begin.


Step D must be finished before step Q can begin.


Step F must be finished before step B can begin.


Step I must be finished before step R can begin.


Step Y must be finished before step I can begin.


Step M must be finished before step D can begin.


Step F must be finished before step U can begin.

Reference in new issue