File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed
src/main/scala/eu/sim642/adventofcode2018 Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -17,18 +17,16 @@ object Day7 {
17
17
18
18
def parallelTopologicalSort (reqs : Requirements , workerCount : Int = 5 , baseStepTime : Int = 60 ): Int = {
19
19
20
- case class Work (step : Step , timeLeft : Int )
20
+ case class Work (step : Step , timeLeft : Int ) {
21
+ def ticked (time : Int ): Work = copy(timeLeft = timeLeft - time)
22
+ }
21
23
22
24
def tickTime (reqs : Requirements , works : Set [Work ]) = {
23
- works.foldLeft((reqs, Set .empty[Work ]))({
24
- case ((reqs, works), Work (step, timeLeft)) =>
25
- if (timeLeft == 0 ) {
26
- val restReqs = reqs.filterKeys(_ != step)
27
- (restReqs, works)
28
- }
29
- else
30
- (reqs, works + Work (step, timeLeft - 1 ))
31
- })
25
+ val (endWorks, tickWorks) = works.partition(_.timeLeft == 0 )
26
+ val endSteps = endWorks.map(_.step)
27
+ val restReqs = reqs -- endSteps
28
+ val tickedWorks = tickWorks.map(_.ticked(1 ))
29
+ (restReqs, tickedWorks)
32
30
}
33
31
34
32
def pickWork (reqs : Requirements , works : Set [Work ]) = {
You can’t perform that action at this time.
0 commit comments