BQN: Can less code do more?
HTML-код
- Опубликовано: 6 фев 2025
- I take my BQN Advent of Code 2023 Day 2 Part 1 solution and make it shorter. Does it end up being more readable?
This is a follow up of my BQN AoC '23 Day 2 Part 1: • BQN: Solving Advent of...
BQN: mlochbaum.gith...
@code_report 's video where it goes from Python to BQN • Why I Love BQN So Much... All his videos (and podcasts!) are great, please check it out!
{𝕊a‿b:a⋈b} (I've used ⋈ instead of ≤⟜Lookup) documents and checks the structure of the argument in a way tacit code usually doesn't. Knowing that structure (a pair), we can tell that (⊑)⊸(⋈)⟜(1⊸⊑) is equivalent to ⋈´ (fold inserts the function between the items). Another such pattern to look out for is (⊣⋈⊢) which is ⋈. And then there's ⌊´⌊´¨ which can be ⌊´∾ and F¨¨¨ can be F⚇¯3 (and probably some other variants). Tacit code is meant for concise code, not just inlining.
In a very literal sense, less code can indeed do more, as e.g. {𝕊a‿b:a+b} sums two terms, but +´ sums any count.
> Knowing that structure [..] is equivalent to ⋈
That's awesome, thank you!
> And then there's [..]
I'll have to try using ⚇ more because I don't fully understand it, beyond that it saves me repeating ¨ . Thank you for the explanations!
Expressed in somewhat similar Haskell, {𝕊a‿b: a F b} looks like \(a,b) -> a ˋFˋ b, (⊑)⊸(F)⟜(1⊸⊑) looks like F fst snd, and F´ looks like uncurry F.
@@0LoneTech That makes more sense, thank you!