Skip to content

Instantly share code, notes, and snippets.

@jcmorrow
Created December 14, 2020 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcmorrow/5cd4401b22e13236be67b8ec349f1877 to your computer and use it in GitHub Desktop.
Save jcmorrow/5cd4401b22e13236be67b8ec349f1877 to your computer and use it in GitHub Desktop.
input =: ,.LF cut fread '~/code/advent_of_code/day_12.txt'
i =: 0 j. 1
move =: 1 0 0;0 1 0;(,&0 1)
turn =: 1 0 0;;&0 0 1@(0,(,&0))
F =: 1 0 0;0 0 1(;~)0(,~)1&(,~)
E =: move@(1&*)
N =: move@(i&*)
S =: move@((-i)&*)
W =: move@(_1&*)
R =: turn@((-i)&^@(%&90)))
L =: turn@((i)&^@(%&90))
op =: {.
arg =: ".@:}.
do =: monad : '(>{.y)~ (>}.y)'
transforms =: ,.<"2 (786 3 3 $ ;; do @ (op ; arg) &.> input)
matmul =: dyad : 'y +/ . * (3 3 $;>x)'
+/ | +. {. 0 1 1 matmul F.. ] transforms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment