From: Ben Harris Date: Mon, 27 May 2024 10:40:14 +0000 (+0100) Subject: 19a gets the example blueprint 1 right X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=88a11131affb5a6d30a70d9b0297d5b58db8ef1b;p=aoc-2022.git 19a gets the example blueprint 1 right Takes 17.8 seconds to do so. --- diff --git a/19/19a.bqn b/19/19a.bqn index 1b8b267..88e75bf 100644 --- a/19/19a.bqn +++ b/19/19a.bqn @@ -4,13 +4,23 @@ robot_costs ← [⟨4,0,0,0⟩,⟨2,0,0,0⟩,⟨3,14,0,0⟩,⟨2,0,7,0⟩] -Search←{ - 𝕊⟨·,stock,·⟩: ∨´0>stock ? ¯∞; # Bankruptcy is undesirable. - 𝕊⟨0,stock,·⟩: 3⊑stock; +# 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⟩: - •Show ⟨time,stock,robots⟩ - ⌈´Search¨⟨⟨time-1,stock+robots,robots⟩⟩∾{ - ⟨time-1,stock+robots-𝕩⊏robot_costs,(1⊸+)⌾(𝕩⊸⊑)robots⟩}¨↕≠robot_costs + 3⊑stock+robots×time # If not, return number of geodes we can get in time. } -•Show Search ⟨5,⟨0,0,0,0⟩,⟨1,0,0,0⟩⟩ +•Show Search ⟨24,⟨0,0,0,0⟩,⟨1,0,0,0⟩⟩