Skip to content

Instantly share code, notes, and snippets.

@rak1507
rak1507 / day 7.apl
Last active December 7, 2022 18:23
⍝ approach 1
M←⎕json⍠'M'⎕json r⊣{⍺≡'$ cd ..':⍵.##⋄'$'≡⊃⍺:⍵⍎5↓⍺,'←⎕ns⍬'⋄'d'≢⊃⍺:⍵⊣⍵⍎1↓∊'←',¨0(7162⌶)¨@0⌽' '(≠⊆⊢)⍺⋄⍵}/(r←⎕ns⍬),⍨⌽1↓'$ ls'~⍨⍥⊆⊃⎕NGET'7.txt'1
sizes←(∊↑M[;2])+.×⍨{⍵∧∧\1,2≤/⍵}≠\(1=⊢/M)⌿(∘.≤⍨⍳≢M)×∘.≥⍨⊣/M
({+/⍵/⍨⍵≤1e5}, {⌊/⍵/⍨⍵≥4e7-⍨⊃⍵}) sizes
⍝ approach 2
depth type size←{(+\type) (type←(('$ cd'≡4↑⊢)ׯ1*'.'∊⊢)¨⍵) ({⊃⊃⊢/⎕vfi ⍵}¨⍵)}⊃⎕nget'7.txt'1
sizes←(1=type)/size+.×⍨{{⍵∧∧\1,2≤/⍵}(∘.≤⍨⍳≢⍵)×∘.≤⍨⍵}depth
({+/⍵/⍨⍵≤1e5}, {⌊/⍵/⍨⍵≥4e7-⍨⊃⍵}) sizes
@rak1507
rak1507 / aoc.py
Last active December 11, 2021 18:56
#day 1
*a,=map(int,open(0))
print(sum(i<j for i,j in zip(a,a[1:])))
print(sum(i<j for i,j in zip(a,a[3:])))
#day 2
from itertools import accumulate
print(sum(d:=[1j**'fd'.find(i[0])*int(i.split()[1]) for i in open(0)]).real*sum(d).imag)
print(sum(i.real*j.imag for i,j in zip(d, accumulate(d)))*sum(d).real)
Introduction: Stephen Taylor
I want to share with you a tiny origin story that literally no one else in the world knows. There’s an example there of a function being applied to a list of strings, cow, sheep, cat, dog. I’ve often used that list of words in demos and code examples, it comes from a school review in 1965. My friend was introduced, Michael Simpson will now say a few words. Michael walked up to the microphone and said “cow, sheep, cat, dog”.
Conor Hoekstra:
Alright, welcome to the first episode of ArrayCast, a podcast about array programming languages and the array programming paradigm. My name is Conor Hoekstra, I’ll be your host for today and I think all of the following episodes, and we’re going to go around and do brief introductions with my three cohosts. We’ll go in the order of Stephen, Adám, and then Bob.
Stephen Taylor:
Hello, I’m Stephen Taylor, I learned, I was shown APL a long time ago, hundreds of years ago I think, back in the days of timesharing services and teletypes, and I immedia