David Lambert/AOC

From J Wiki
Jump to navigation Jump to search

https://adventofcode.com/2020/day/11

A=:[;._1 LF,CR-.~1!:1<'d:/tmp/seats'
frame=: ' ' , ' ' ,~ ' ' ,. ,.&' '
sit=:'#'"_
stand=:'L'"_
stay=:4{,
f=:(1 1,:3 3) (sit`stay`stay`stay`stay`stay`stand`stand`stand`stand`stand@.(('#'=stay)+([:+/'#'=,)))`('.'"_)@.('.'=stay);._3 frame
NB. (1 1,:3 3) (sit`stay`stay`stay`stay`stay`stand`stand`stand`stand@.(('#'=stay)+([:+/'#'=,)))`('.'"_)@.('.'=stay);.
part1=:(1 1,:3 3) (sit`stay`stay`stay`stay`stay`stand`stand`stand`stand`stand@.(('#'=stay)+([:+/'#'=,)))`('.'"_)@.('.'=stay);._3 frame

 +/'#'=, part1^:_ A  NB. ???

part2=:(sit`stay`stay`stay`stay`stay`stay`stand`stand`stand`stand@.(('#'=stay)+([:+/'#'=,)))`('.'"_)@.('.'=stay) NB. y is vector of visible chars
frame2=: 'L' ,~ ,.&'L'
COORDS=:(4$.$.)1$~$A

main=: 3 :0
 shape=. $ y
 +/'#'=,(shape $ COORDS part2@search"1 _ frame2)^:_ y
)

search=. 4 :0  NB. COORD search GRID    to do: replace loops with fold

 L=. #\i.92

 rv=. ,''

 for_i. L do.    NB. 0
  c=. (<x + 0 1 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 for_i. L do.    NB. 1
  c=. (<x + _1 1 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 for_i. L do.    NB. 2
  c=. (<x + _1 0 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 for_i. L do.    NB. 3
  c=. (<x + _1 _1 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 rv=. rv , (<x){y

 for_i. L do.    NB. 5
  c=. (<x + 0 _1 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 for_i. L do.    NB. 6
  c=. (<x + 1 _1 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 for_i. L do.    NB. 7
  c=. (<x + 1 0 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 for_i. L do.    NB. 8
  c=. (<x + 1 1 * i) { y
  if. c ~: '.' do.
   rv=. rv , c
   break.
  end.
 end.

 rv

)