I'm learning BQN, trying to refactor my solution for the first Project Euler problem into a single tacit binary function: 3‿5 𝔽 100
+´ ×⟜(∨´ 0 = 3‿5 | ⊢)¨ ↕100
But BQN has no combinators like this: 𝕩 𝔽 (𝕨 𝔾 𝕩)
And I don't know what it's usually called either. Could implement if ofc, but I want to stay point-free all the way :[
#bqn #programming #functionalprogramming
Absolute kudos to #BQN for making an accessible tutorial for an array programming language! https://mlochbaum.github.io/BQN/doc/quick.html
Yes, it requires concentration...but it's incredibly clear. And you don't build factorial, game of life, or fizzbuzz!
Finished up day 13 of #adventofcode in #bqn today!
This was kinda interesting. The semantic of BQN's sort *almost* matches the sort required. Unlike some others I didn't get lucky and get an input that didn't exercise the edge cases where it doesn't, so I had to implement my own merge sort with a custom comparator.
Aaand, here's my day 12 solution to #adventofcode in #bqn
This time I'm using an interesting algorithm that I've not seen much outside of #gamedev circles focused on #roguelike games, a Dijkstra Map!
It's a way of precomputing paths to points of interest from any point in the map by performing something close to a flood-fill starting from points of interest.
#adventofcode #bqn #gamedev #roguelike
Well it's taken me a couple days to catch back up, but I'm back on #adventofcode with #bqn
Here's my solution to day 11, which I feel pretty gross about.
I'm normally not a fan of OOP, but it ended up being the only way I could determine to solve this in a reasonable amount of code, so I used the mutable namespaces of BQN to solve the problem.
Yesterday I didn't do the #adventofcode day 10, but I finished it this morning with #bqn
It ended up pretty fun! I used continuation passing style, and this is the first time that's seemed useful to me.
Today's solution got back into the realm of too large for a toot, but I'm still going strong with #adventofcode in #bqn !
This one was pretty fun because it used the same code for both segments, I just had to adjust my first solution for part 2 very slightly to use a scan.
Today my solution in #bqn for #adventofcode is small enough to fit in a toot again!
Part1 ⇐ {
d ← > '0'-˜𝕩
+´ ⥊ ⊑ ∨˝ {(∊⌈`)˘⌾(⍉∘⌽⍟𝕩)d}¨ ↕4
}
Score ⇐ {
x‿y 𝕊 𝕩:
h ← (⌽𝕨) ⊑ 𝕩
row ← 𝕩⊏˜y
col ← (⍉𝕩)⊏˜x
up ← ⌽y↑col
down ← col↓˜1+y
left ← ⌽x↑row
right ← row↓˜1+x
×´ { ((1∘⊑⟜𝕩)⎊0)⊸+ ⊑ (0⊐˜h>𝕩) }¨ up‿down‿left‿right
}
Part2 ⇐ {
d ← > '0'-˜𝕩
is ← ⌽¨ ⥊ ↕≢d
⌈´ Score⟜d¨ is
}
Today's #adventofcode almost beat me, but I managed to best it with #bqn !
Working with trees is pretty hard, and I almost gave up after I forgot to take into account files that are stored in the root of the filesystem.
Did day 6 of #adventofcode in #bqn, this solution is probably a little longer than it needs to be, but I'm satisfied enough with it.
Marker ← {
⊑ 𝕨 + 1 ⊐˜ 𝕨 = (≠·(1=+´˘)⊸/=⌜˜)˘ 𝕨↕ ⊑ 𝕩
}
Part1 ⇐ 4⊸Marker
Part2 ⇐ 14⊸Marker
Unfortunately today is the first day that my solution to #adventofcode in #bqn doesn't fit in a toot, so today I share a screenshot!
This clocks in at 527 characters, just too large.
And now to day 4 of #adventofcode in #bqn
Today I feel a little less good about the solution here, I feel there should be more that I can do to shorten it, but I didn't think it worth the effort.
ParseLine ← common.ParseNumber¨·>'-'common.SplitAt¨','common.SplitAt⊢
Contains ← {a‿b 𝕊 x‿y: (a ≤ x) ∧ b ≥ y}
Part1 ⇐ +´ ((Contains˜∨Contains)˝ ParseLine)¨
Overlap ← {a‿b 𝕊 x‿y: ((a⊸≤∧b⊸≥) x)∨((a⊸≤∧b⊸≥) y)∨(x‿y Contains a‿b)}
Part2 ⇐ +´ (Overlap˝ ParseLine)¨
I missed posting it yesterday, so I'll probably post twice today: #adventofcode in #bqn day 3:
Priority ← 'a'‿('z'+1)⊸common.InRange◶(27+'A'-˜⊢)‿(1+'a'-˜⊢)
Part1 ⇐ +´ {
⌈´ ⌈˝(=◶0‿priority)⌜˝ 2‿∘⥊ 𝕩
}¨
Part2 ⇐ {
⊑ +˝ Priority¨ { (⍷⊢/˜⊐<·≠⊣)˝ > (⊢⥊˜¨⌈´∘(≠¨)) ⍷¨ 𝕩 }˘ ∘‿3⥊ 𝕩
}
I finished my day 2 solution for #adventofcode in #bqn
Like last time there's a little bit of library code, and I've left off the import this time.
GenerateOffsets ← 'A'‿'X'-˜¨·>' 'c.SplitAt⊢
Part1 ⇐ +´∘(⊑¨) {
((⊑1⊏⊢)+3×3|(⊣-˜1⊸+)˝) 1 + GenerateOffsets 𝕩
}¨
Part2 ⇐ +´∘(⊑¨) {
1 + ((3×·⊑1⊏⊢)+(3|⊣-1-⊢)˝) GenerateOffsets 𝕩
}¨
I finished up the day 1 problem for advent of code in #bqn
There's a little bit of library code I have from my other years, but they're pretty obvious in meaning here.
c ← ⟨⟩ •Import "../common.bqn"
Calories ← +´¨·(c.ParseNumber⚇1)⟨⟩⊸c.SplitAt
Part1 ⇐ ⌈´Calories
Part2 ⇐ +´3⊸↑∘∨∘Calories
I'm getting super excited for #adventofcode this year, just brushing up on my #bqn knowledge and tooling. It'll be really cool to have an #apl family language as my language of choice for it this year.
What languages are you looking to use, if you plan to participate?