I still feel like I can get this cleaner. I did tr...
# advent-of-code
t
I still feel like I can get this cleaner. I did try to write one function to do both parts and just change the workers and costing function, but abandoned that because it didn't immediately work, and I'm not convinced I can explain it succinctly when I blog about it later.
a
Well Done. You should be able to solve Part 1 just by passing a workers = 1 & a cost function which returns zero regardless of the character. You will possibly need to change the return from your function to yield a sequence which returns a Pair containing the character which has been completed and the 'finish' time of the character
Bit confused with the loop in your code as it always seems to take 5 items from the available list. How do you keep track of when the workers have finished?
t
Yeah I tried that and something about the way I schedule work in part 2 didn't work because the order was always different.
Workers finish when their cost gets down to zero.
We are always working at the head of the queue and replacing them with cost-1 items in place.
a
Ok, so the loop is acting like a 1 second clock?
t
Yes. Probably more work than is really needed, but was easier for me to reason about.
a
Looking at the way my data acts I don't think that there are ever more than 5 items ready to be processed. This means that there is never an entry waiting for an elf to finish work. If you assume this then the problem is simply a graph algorithm to find the longest path from start to finish.
Probably just as well as I don't think my algorithm would have found the result otherwise 🙂
t
Huh. Might go back and re look at part 2 with that graph observation in mind.
k
For my data the 5th worker never even does any work.
1
t
Maybe try some personal coaching to see if you can up their performance.
k
Haha I got that notification and I was really confused until I saw the context.
t
TBH that’s my aim with comments like that. 🙃
g
Lucky I saw this thread, my code was bugged, actually had +1 workers, selved now
In my case only 4 workers are busy most at the same time
👍 2