Stage Build, Part 1
The puzzle
A village is putting up an open-air stage for its summer concert. The crew lead has written every task on a card: its name, how many hours it takes, and which tasks must be finished before it can start.
footings 3:
scaffold 2: footings
roof 5: scaffold
power 1:
lights 3: roof power
Plenty of volunteers have turned up, so any task whose earlier tasks are all finished can start straight away, alongside any others. Work starts at hour 0. In the small plan above, lights can't start before hour 10 (it waits for roof, which ends at 3 + 2 + 5), even though power is done at hour 1, so the whole plan is ready at hour 13.
How many hours until the whole stage, this lesson's input, is ready?
The cards were written in a hurry. If a card waits for a task that has no card, or some tasks end up waiting for each other in a circle, the plan can't be built, and your program should say so.
Task
- Complete
parseTask(line string) (Task, error): read a card such aslights 3: roof power. Before the colon there must be exactly a name and a whole number of hours (1 or more); after it come the tasks it waits for, possibly none. - Complete
earliestEnds(tasks map[string]Task) (map[string]int, error): the earliest hour each task can be finished. Return an error for a task that waits for an unknown task, and for tasks that wait in a circle. - Complete
finish(tasks map[string]Task) (int, error): the earliest hour the whole stage is ready.