Skip to content

Instantly share code, notes, and snippets.

@jcmorrow
Created December 11, 2020 07:39
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/b042608a5bb1d6012029d0011793140e to your computer and use it in GitHub Desktop.
Save jcmorrow/b042608a5bb1d6012029d0011793140e to your computer and use it in GitHub Desktop.
seats =: (90 91 $ ;'L' = &> ;(LF cut fread '~/code/advent_of_code/day_11.txt'))
is =: dyad : '+/ ;x = ;y'
pad =: monad : '|:0,|: 0, y'
unpad =: monad : '(<:$ y) $ (0 0 ,: <:$ y) ,;.0 y'
tile =: monad : ';"2 (1 1,: 3 3) ];.3 y'
count =: dyad : '(x is &> <"1 y)'
step =: monad define
occupied =. unpad 2 count tile pad y
comingAlive =. (y = 1) * (0 = occupied)
dying =. (y = 2) * (4 < occupied)
stayingAlive =. (y = 2) * (4 >: occupied)
dying + (comingAlive +. stayingAlive) * 2
)
s =: seats
ex =: monad define
s =: step s
+/ ;2 = s
)
}. ,.ex &> i.100 NB. just do it a bunch of times until it stops changing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment