From: Ben Harris Date: Mon, 27 May 2024 12:51:44 +0000 (+0100) Subject: 19a done X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=ae8e07f26b5971bab2e69703c3c8d3b33cf57618;p=aoc-2022.git 19a done --- diff --git a/19/19a.bqn b/19/19a.bqn index 88e75bf..28be0de 100644 --- a/19/19a.bqn +++ b/19/19a.bqn @@ -1,26 +1,48 @@ -# Material types are ore, clay, obsidian, geode. +Split←{ + blocknums ← +`𝕨 + # Set entries in blocknums to -1 when they correspond with delimiters. + blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums + blocknums⊔𝕩 +} -# Initially just handle the first blueprint. +# Material types are ore, clay, obsidian, geode. -robot_costs ← [⟨4,0,0,0⟩,⟨2,0,0,0⟩,⟨3,14,0,0⟩,⟨2,0,7,0⟩] +# Only the numbers differ between blueprints. +Prep←{ + words←(' '=𝕩)Split 𝕩 + •ParseFloat¨(⋈¨[⟨6, ¯1,¯1,¯1⟩, + ⟨12,¯1,¯1,¯1⟩, + ⟨18,21,¯1,¯1⟩, + ⟨27,¯1,30,¯1⟩])⊑words∾⟨"0"⟩ +}¨ # 0÷0 is NaN. But for our purposes we want it to be 0. NtZ←{=˜𝕩 ? 𝕩; 0}¨ # NaN is not equal to itself. -Search←{ 𝕊⟨time,stock,robots⟩: - #•Show ⟨time,stock,robots⟩ - result←⌈´{ - needed←(𝕩⊏robot_costs)-stock - needed_time←1+0⌈⌈´⌈NtZ needed÷robots - needed_time≤time ? # If there's enough time, built a robot. - Search ⟨time-needed_time - (stock+robots×needed_time)-𝕩⊏robot_costs - (1⊸+)⌾(𝕩⊸⊑)robots⟩; - ¯∞ # No time to built this kind of robot. - }¨↕≠robot_costs - result≥0 ? result; # Return if any robot can be built. - 𝕊⟨time,stock,robots⟩: - 3⊑stock+robots×time # If not, return number of geodes we can get in time. +EvalBlueprint←{𝕊 robot_costs: + max_costs←⌈´˘robot_costs + Search←{ 𝕊⟨time,stock,robots⟩: + #•Show ⟨time,stock,robots⟩ + result←⌈´{ + needed←(𝕩⊏robot_costs)-stock + needed_time←1+0⌈⌈´⌈NtZ needed÷robots + # Build a robot if there's time and we might need it. + (needed_time≤time)∧(𝕩⊑stock