Also pretty crude,  in one self-contained routine,  "move" .
It was fast and slim enough for its purpose!

   $data
137 139
   ts'move data'
0.0623268 1.69075e6
   timer'move data'
+---------+---+
|0.0669937|412|
+---------+---+

move =: 3 : 0     NB. long-winded but never mind
_ move y          NB. default to running until no moves available
:
'm n' =. mn =. $ c   =. y -."1 ' '
ixc   =. i. mn                 NB. work on indices
enbs  =. ,1 |."1 ixc           NB. ravel all east neighbours
snbs  =. ,1 |.   ixc           NB.   and all south
ie    =. I. e  =. ,c = '>'     NB. ie holds all east indices
is    =. I. s  =. ,c = 'v'     NB. and is all south ...
iall  =. ie, is                NB. list of all occupied slots
old   =. /:~iall               NB. for checking end condition
ct    =. 1                     NB. counter - could have used x
while. 0 <: x =. <: x do.
   emvok =. iall -.@e.~ newie =. ie { enbs   NB. check occupancy of all of easts' neighbours    ie    =. (ie#~ -.emvok) , newie#~ emvok   NB. crude derivation of the new east positions
   iall  =. ie, is                           NB. reset list of all posns

NB.   similar steps for south facing set
   smvok =. iall -.@e.~ newis =. is { snbs
   is    =. (is#~ -.smvok) , newis#~ smvok
   iall  =. /:~ ie, is                       NB. only needs sort for quick comparison with old

   if. iall -: old do. break. end.

   ct    =. >: ct              NB.  ready for next loop
   old   =. iall
end.
NB. c =. mn $ 'v' is } '>' ie } , mn$'.'     NB. not needed, but reformat from indices to graphic
ct                             NB. return the count
)

For part 2,  I was a bit miffed to be told I needed another star,  the one I missed for day 23 part 2.
<<  NB. my NB.s  ...
NB. The experimental antenna control console lights up again:
NB. Energy source detected.
NB. Integrating energy source from device "sleigh keys"...done.
NB. Installing device drivers...done.
NB. Recalibrating experimental antenna...done.
NB. Boost strength due to matching signal phase: 1 star
NB. Only 49 stars to go.
NB. You don't have enough stars to boost the signal, though. You need 1 more.
>>

Ah well.  Cheers,

Mike

On 15/01/2022 18:24, Raul Miller wrote:
https://adventofcode.com/2021/day/25

This is the end of the advent of code series for last year. It was a
quick wrap up.

Here, the puzzle was about waiting for sea cucumbers to get out of the
way so you could land your submarine and launch santa's sleigh (which
makes about as much sense as santa, but whatever...).

sample=:];._2 {{)n
v...>>.vv>
.vv>>.vv..
.>v>...v
v>>.>.v.
v>v.vv.v..
.>>..v...
.vv..>.>v.
v.v..>>v.v
....v..v.>
}}

For this, I just built a quick step function, ran it until it stopped
and counted the steps:

stepEast=: {{
   '>' stepHalf y
}}

stepSouth=: {{
   |:'v' stepHalf|:y
}}

stepHalf=: {{
   b=. }:"1 (x,'.') E."1 y,.{."1 y
   I=. I.,b
   I2=. I.,_1 |."1 b
   ($y)$ '.' I} x I2} ,y
}}

step=: {{
   N=:N+1
   chk=. #/.~,'.>v',,y
   r=.stepSouth r0=.stepEast y
   assert. chk-:#/.~,'.>v',,r0
   assert. chk-:#/.~,'.>v',,r
}}

a25=: {{
   N=:0
   step^:_ y
   N
}}

Crude, of course, but perhaps appropriately silly?

Anyways... that wraps it up. The second part of the puzzle was to
finish up all the other days and then remotely start the sleigh.

FYI,



--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to