From 34391abd0937b643ab1550b65cda5327b9c6de66 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 28 May 2024 09:32:22 +0100 Subject: [PATCH] 19b done (committed late because I forgot) --- 19/19b.bqn | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 19/19b.bqn diff --git a/19/19b.bqn b/19/19b.bqn new file mode 100644 index 0000000..90d075f --- /dev/null +++ b/19/19b.bqn @@ -0,0 +1,48 @@ +Split←{ + blocknums ← +`𝕨 + # Set entries in blocknums to -1 when they correspond with delimiters. + blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums + blocknums⊔𝕩 +} + +# Material types are ore, clay, obsidian, geode. + +# 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. + +EvalBlueprint←{𝕊 robot_costs: + •Show robot_costs + •Show max_costs←⌈˝(robot_costs∾[⟨0,0,0,∞⟩]) # Want all the geodes. + 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+robots×time)