chiark / gitweb /
19b done
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 26 May 2024 13:26:54 +0000 (14:26 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 26 May 2024 13:26:54 +0000 (14:26 +0100)
18/18b.bqn [new file with mode: 0644]

diff --git a/18/18b.bqn b/18/18b.bqn
new file mode 100644 (file)
index 0000000..11afbba
--- /dev/null
@@ -0,0 +1,33 @@
+Split←{
+  blocknums ← +`𝕨
+  # Set entries in blocknums to -1 when they correspond with delimiters.
+  blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums
+  blocknums⊔𝕩
+}
+
+Prep←{
+  cubes←{
+    •ParseFloat¨(','=𝕩)Split 𝕩
+  }¨𝕩
+  # We assume that all co-ordinates are non-negative.
+  # "3" here allows a margin for flow all round the droplet.
+  droplet←(3+⌈˝>cubes)⥊0
+  droplet↩1¨⌾((1+cubes)⊸⊑)droplet
+}
+
+Main←{ 𝕊 droplet:
+  steam←1⌾(0⊸⊑∘⥊)(≢droplet)⥊0
+  Flood1←{ droplet 𝕊 steam:
+    (¬droplet) ∧ steam ∨ ∨´{(«∨»)⎉𝕩 steam}¨1+↕=𝕩
+  }
+  Flood←{ droplet 𝕊 steams:
+    (<droplet Flood1 ⊑steams)»steams
+  } •_while_ { droplet 𝕊 steams:
+    ≢´steams
+  }
+  ⟨steam,·⟩ ↩ droplet Flood ⟨steam,@⟩
+  NSurfacesInDir←{ +´⥊𝕩≠»𝕩 }
+  +´ NSurfacesInDir¨ ⍉⍟(↕=droplet) ¬steam
+}
+
+•Show Main Prep •file.Lines ⊑•args