2022-08-29: BQN and Project Euler Problems

Long time no post.

I've been playing with a new array programming language called BQN, and trying to solve Project Euler problems with it.

# Calculate the nth Fibonacci number by repeatedly adding a list with
# its reverse and keeping the first number.  (Shamelessly stolen from
# Rosetta Code).
Fib ← { ⊑ (+`⌽)⍟𝕩 0‿1 }

# Extract the numbers of the right hand argument that are smaller than
# the left hand argument.
Smaller_Than ← { (𝕨⊸>)⊸/ 𝕩 }

# Extract only the even numbers from a list.
Evens ← (¬¨2⊸|)⊸/

# Sum up a list.
Sum ← +´

# The answer is…
answer ⇐ Sum Evens (4e6⊸Smaller_Than) Fib¨ ↕100
•Show answer

I really rather like it! It is a fun little programming language and I'd like to do more with it. The Fibonacci generator I stole, but it was fun digging into *why* it works (the repeat operator does 𝕨 𝕩 times, and the first (⊑) of the reversed accumulation (+`⌽) is the next Fibonacci number). The rest I figured out by fiddling.

Realizing I can use replicate (/) to select elements (if you replicate an element 0 times you effectively remove it) was cool too. Fun. Yeah... just fun.

(Still no taste, but a *wee* bit less depressed!)

BQN => https://mlochbaum.github.io/BQN/index.html

Project Euler =