-
-
Save jcmorrow/b042608a5bb1d6012029d0011793140e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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