Skip to content

Commit

Permalink
feat: better text.
Browse files Browse the repository at this point in the history
  • Loading branch information
Panadestein committed Feb 5, 2025
1 parent 20a0b75 commit 8a7e900
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/bqn/rollim.bqn
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ HS ← +´∨≥1+⊒˜
HLHS {𝕎_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]
17 changes: 12 additions & 5 deletions src/rollim.org
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
Expand Down

0 comments on commit 8a7e900

Please sign in to comment.