Skip to content

Instantly share code, notes, and snippets.

@rdm
Created December 5, 2022 20:41
Show Gist options
  • Save rdm/14c19b14ce2e236197df67b37b1df4f4 to your computer and use it in GitHub Desktop.
Save rdm/14c19b14ce2e236197df67b37b1df4f4 to your computer and use it in GitHub Desktop.
aoc 5 (2022)
sample=: {{)n
[D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
}}
input=: fread '~/Downloads/input.txt'
parse=: {{
split=. 2+I. LF2 E. y
dia=: }:];._2 split{.y
moves=: ];._2 split}.y
struct=: {: dia
mask=: ' '~:struct
cols=: mask#struct
stacks=: <@deb"1 mask#|:}:dia
moves
}}
from=: to=: ,
move=: {{
'quant a b'=. y
'src dst'=. cols i.a,&":b
source=: src{::stacks
dest=: dst{::stacks
dest=: (|.quant{.source),dest
source=: quant}.source
stacks=: (<source) src} (<dest) dst} stacks
EMPTY
}}
move=: {{
'quant a b'=. y
'src dst'=. cols i.a,&":b
source=: src{::stacks
dest=: dst{::stacks
dest=: (quant{.source),dest
source=: quant}.source
stacks=: (<source) src} (<dest) dst} stacks
EMPTY
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment