Advent of Code 2022 in APL & BQN Day 6!
Vložit
- čas přidán 27. 06. 2024
- In this video I cover the APL & BQN solutions to Problem A and B from Day 6 of Advent of Code 2022.
AoC GitHub Repo: github.com/codereport/Advent-...
APL Solution: github.com/codereport/Advent-...
BQN Solution: github.com/codereport/Advent-...
Problem Statement: adventofcode.com/2022/day/6
How to Install APL RIDE: • How To Install APL
Dyalog APL: www.dyalog.com/
Dyalog RIDE: github.com/Dyalog/ride
BQN: mlochbaum.github.io/BQN/
BQNPAD: bqnpad.mechanize.systems/
Chapters:
0:00 Intro / Problem Description
0:50 APL Solution
5:15 BQN Solution
Follow me on Github: github.com/codereport
Follow me on Twitter: / code_report
Follow me on LinkedIn: / codereport
What kind of sorcery did I just stumble upon :O
You can also move the unique into the windowed reduce by using union, which discards all duplicates as it concatenates.
In J I did this: [ + 1 i.~ (-:~.)\
Instead of an n-wise reduce, J has the more general infixes operator which applies an arbitrary function (not necessarily a reduction) to all windows of a given length. Here I apply the function (-:~.) which checks if the widow is equal to its deduplication.
Can someone please explain if there is a way to clear the screen on the RIDE editor? I've been learning apl recently and find having hundreds of lines from previous sessions annoying.
the way I did it, was by replacing the comma with the union to get the unique for each; not need to first group then unique when you can do it in one step
Using your refactor, it looks like this: Solution ← {¯1+⍺+⍺⍳⍨≢¨⍺ ∪/⍵}
I am new to apl and I want to ask why is the composition ○ required for the tally?
what happened to day 5?
we don't talk about day 5
Day 5 is about 100x harder than this in an array language lol
chatgpt suggested
detect_marker_position ← { ⊂/≠⍵[1+⍳4] }
it looks correct?
The First of the Where is a bit wasteful, as it'll look for all the 1s rather than stopping when it finds the first 1 whereas 1⍳⍨ will stop immediately when a 1 is found. And as for code golf: ⊣-1-1⍳⍨∪/∊,/