chiark / gitweb /
14a done
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 14 May 2024 14:58:00 +0000 (15:58 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 14 May 2024 14:58:00 +0000 (15:58 +0100)
14/14a.bqn

index 407a672ed7e621687486a751de037a2cf18d98d1..6248c22fa4482c8cb10c0eb538aa7912667b545d 100644 (file)
@@ -29,7 +29,26 @@ Plot←{
   {𝕊⟨from,to⟩:
     map ↩ 1¨⌾((from RectIndices to)⊸⊑) map
   }˘∾2↕¨𝕩
-  map⊏".#"
+  map
 }
 
-•Show Plot Prep •file.Lines ⊑•args
+Main←{𝕊map:
+  grains←0
+  Settle←{
+    map 1⌾(𝕩⊸⊑) ↩
+    grains +↩ 1
+    1
+  }
+  # Return 0 if the sand falls forever; 1 once a path is full.
+  OnMap←{ (∧´𝕩≥⟨0,0⟩)∧(∧´𝕩<≢map) } # 0 if fallen off the map.
+  Solid←{ 𝕩⊑map } # Hit something solid.
+  FilledDown ←{Pour  ⟨0,1⟩+𝕩}
+  FilledLeft ←{Pour ⟨¯1,1⟩+𝕩}
+  FilledRight←{Pour  ⟨1,1⟩+𝕩}
+  Pour← OnMap _and_and_ (Solid _or_or_ (FilledDown _and_and_ FilledLeft _and_and_ FilledRight _and_and_ Settle))
+  Pour ⟨500,0⟩
+  #•Show (400↓map)⊏".#"
+  grains
+}
+
+•Show Main Plot Prep •file.Lines ⊑•args