diff --git a/src/bqn/rollim.bqn b/src/bqn/rollim.bqn index 48919b3..d8f9ea3 100644 --- a/src/bqn/rollim.bqn +++ b/src/bqn/rollim.bqn @@ -60,3 +60,5 @@ HS ← +´∨≥1+⊒˜ HL‿HS {𝕎•_timed𝕩}¨< 1e8 •rand.Range 1e3 (+´⊢-˜⌈`⌾⌽⌊⌈`) [0,1,0,2,1,0,1,3,2,1,2,1] + +(+´⊢-˜⌈`⌾⌽⌊⌈`) [1,8,6,2,5,4,8,3,7] diff --git a/src/rollim.org b/src/rollim.org index dd16300..acd3c5c 100644 --- a/src/rollim.org +++ b/src/rollim.org @@ -274,8 +274,8 @@ I initially clip my citations array with ={≠¨⊔≠∘𝕩¨⌾(≥⟜≠∘ ** Trapping rain water -This problem is a classic in the realm of algorithms, and it can be solved in linear time. Interestingly, -it admits a very elegant array solution as well: +This is a classical interview problem that can be solved in linear time. Interestingly, +it admits a very elegant array solution: #+begin_src bqn :tangle ./bqn/rollim.bqn :exports both (+´⊢-˜⌈`⌾⌽⌊⌈`) [0,1,0,2,1,0,1,3,2,1,2,1] @@ -284,9 +284,16 @@ it admits a very elegant array solution as well: #+RESULTS: : 6 -That is, we do a max scan from the left and from the right, and then take the minimum of the two, -then we subtract the height of the building at that point. The sum of all these values is the answer. -A closely related problem is [[https://leetcode.com/problems/container-with-most-water/][container with most water]], which can be solved: +That is, we take the minimum of max scans from the left and from the right, and subtract the corresponding height. +Folding sum over the result gives the answer. A closely related problem is [[https://leetcode.com/problems/container-with-most-water/][container with most water]], which can +be solved in linear time as well: + +#+begin_src bqn :tangle ./bqn/rollim.bqn :exports both + (+´⊢-˜⌈`⌾⌽⌊⌈`) [1,8,6,2,5,4,8,3,7] +#+end_src + +#+RESULTS: +: 19 [fn:1] Almost Perfect Artifacts Improve only in Small Ways: APL is more French than English, Alan J. Perlis (1978). From [[https://www.jsoftware.com/papers/perlis78.htm][jsoftware]]'s papers collection.