Bakery oven racks
MediumOnline Assessment
Simulate a bakery's proofing cabinet and oven, and report what comes out of each load and unload.
recipes is a list of [name, proofMinutes, bakeMinutes, temp]. The oven has racks racks numbered 1 to racks (all empty at the start), and its temperature starts at 0. events is a list of [minute, command], in time order. Commands:
"proof NAME": put a new tray ofNAMEin the proofing cabinet. It is ready from minuteminute + proofMinuteson."load NAME": take a tray ofNAMEthat is ready now out of the cabinet (trays of one recipe are interchangeable) and put it in the lowest-numbered empty rack. Report"loaded R"(the rack number). If no tray ofNAMEis ready, report"not-ready"(this is checked first). If a tray is ready but every rack is full, report"no-rack"; the tray stays in the cabinet."oven T": the oven jumps to temperatureTimmediately. Nothing is reported."unload R": empty rackR. Report"empty"if it had no tray. Otherwise report"NAME ok","NAME raw"or"NAME burnt"as described below.
A tray in a rack bakes during every minute in which the oven temperature is within 10 degrees (inclusive) of the recipe's temp, counting from the minute it was loaded. Time between two events runs at the oven temperature set by the earlier ones, so an oven event changes baking from its own minute on, and a tray loaded at minute m starts accumulating at m. Its baked minutes are the total accumulated when it is unloaded. The tray is raw if baked < bakeMinutes, burnt if baked > bakeMinutes + 5, and ok otherwise.
Input: racks, recipes, events.
Output: a list of strings, one for each load and unload event in the order given (proof and oven add nothing).
Example 1
- Input:
- [2,[["baguette",30,20,230],["roll",20,12,200]],[[0,"oven 225"],[0,"proof baguette"],[5,"proof baguette"],[10,"load baguette"],[30,"load baguette"],[35,"load baguette"],[50,"unload 1"],[55,"unload 2"],[56,"unload 1"]]]
- Output:
- ["not-ready","loaded 1","loaded 2","baguette ok","baguette ok","empty"]
- Explanation
- The oven is 225, within 10 of the baguette temperature 230. The first tray is ready at minute 30, the second at 35, so the load at minute 10 is
not-ready. The trays go to racks 1 and 2 and bake 20 minutes each (30 to 50, 35 to 55): bothok. The last unload finds rack 1 empty.
Example 2
- Input:
- [1,[["baguette",30,20,230],["roll",20,12,200]],[[0,"oven 200"],[0,"proof roll"],[0,"proof roll"],[0,"proof roll"],[20,"load roll"],[25,"oven 150"],[40,"oven 195"],[47,"unload 1"],[47,"load roll"],[48,"load roll"],[60,"unload 1"]]]
- Output:
- ["loaded 1","roll ok","loaded 1","no-rack","roll ok"]
- Explanation
- A roll tray loaded at minute 20 bakes 5 minutes, pauses while the oven is at 150 (minute 25 to 40, out of range) and bakes 7 more until minute 47: 12 minutes, exactly enough, so it is
ok. Rack 1 is free again at minute 47, so the next tray loads there; at minute 48 the rack is full, so the third tray getsno-rackand stays in the cabinet.
Example 3
- Input:
- [2,[["bagel",15,10,220]],[[0,"oven 220"],[0,"proof bagel"],[0,"proof bagel"],[15,"load bagel"],[25,"load bagel"],[32,"oven 260"],[33,"unload 2"],[33,"unload 1"],[33,"unload 1"]]]
- Output:
- ["loaded 1","loaded 2","bagel raw","bagel burnt","empty"]
- Explanation
- The first bagel tray bakes from minute 15 to 32 while the oven is at 220: 17 minutes, which is more than 10 + 5, so it is
burnt. The second, loaded at 25, only gets 7 minutes before the oven jumps to 260, so it israw. Unloading rack 1 a second time finds it empty.
Constraints
1 <= racks <= 6;1 <= recipes.length <= 5; recipe names are distinct lowercase wordsproofMinutes,bakeMinutesare between1and120;tempand everyovensetting are between0and3000 <= events.length <= 300; events are listed in non-decreasing minute order, minutes up to5,000- every
proofandloadnames a recipe fromrecipes; everyunloadnames a rack from1toracks