From: Ben Harris Date: Sat, 4 May 2024 12:02:59 +0000 (+0100) Subject: A bit more Split fettling in 04 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=a730fc5426804996df4b00f312a470c9b2915e26;p=aoc-2022.git A bit more Split fettling in 04 It was silly to have an operator that immediately called its operand on its argument and did nothing else with the operand. Better to have a function that takes the output of the operand as its left argument. That avoids the confusion I had over whether the operator should take a function that acts on a single element or on the whole list: it now takes neither. This doesn't even make calling the function any harder. It just changes F _split x into F⊸Split x. --- diff --git a/04/04a.bqn b/04/04a.bqn index 4e378b4..a278ab9 100644 --- a/04/04a.bqn +++ b/04/04a.bqn @@ -1,12 +1,11 @@ -_split←{ - delims←𝔽𝕩 - blocknums ← +`delims - # Set entries in blocknums to -1 when they correspond with delims. - blocknums ↩ (¯1¨)⌾(delims⊸/) blocknums +Split←{ + blocknums ← +`𝕨 + # Set entries in blocknums to -1 when they correspond with delimiters. + blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums blocknums⊔𝕩 } -Prep←{⍉>•ParseFloat¨¨{𝕩∊",-"}_split¨𝕩} +Prep←{⍉>•ParseFloat¨¨{𝕩∊",-"}⊸Split¨𝕩} Main←{𝕊[x0,x1,y0,y1]: +´((x0≤y0)∧(x1≥y1))∨((y0≤x0)∧(y1≥x1)) diff --git a/04/04b.bqn b/04/04b.bqn index 048a6dc..a89e0e9 100644 --- a/04/04b.bqn +++ b/04/04b.bqn @@ -1,12 +1,11 @@ -_split←{ - delims←𝔽𝕩 - blocknums ← +`delims - # Set entries in blocknums to -1 when they correspond with delims. - blocknums ↩ (¯1¨)⌾(delims⊸/) blocknums +Split←{ + blocknums ← +`𝕨 + # Set entries in blocknums to -1 when they correspond with delimiters. + blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums blocknums⊔𝕩 } -Prep←{⍉>•ParseFloat¨¨{𝕩∊",-"}_split¨𝕩} +Prep←{⍉>•ParseFloat¨¨{𝕩∊",-"}⊸Split¨𝕩} Main←{𝕊[x0,x1,y0,y1]: +´((x0≤y1)∧(x1≥y0))∨((y0≤x1)∧(y1≥x0))