part 1 completes pretty quickly  "manually"

_2&({.\)`([: }. _2 {.\ ])@.(2 | #)^:(1 < #)^:_ i. 3014387

but, this similar approach for part 2 is crazy slow due to n "loops" rewritting 
an n long array

(1 |. ] -. ] {~ <.@-:@#)^:(1 < #)^:_ i.4387



a version that does 2 ^. n "loops", is fast.


f =: 3 : 0
n =. # y
if. 5 > n do. (1 |. ] ({.~ , (}.~ >:)) <.@-:@#)^:(1 < #)^:(_) y return. end.
h =. <.@-: n
'f m' =. 3 (<.@%~ , |) n - h
if. 2 | n do.
(m + 2 *  f) |. (y {.~ -m) , (y }.~ -m) ({.~ , _3 {.\ (}.~ >:)) h
else.
(m + 2 * f) |. (y {.~ -m) , (y }.~ -m) ({.~ , _3 {:\ (}.~ )) h
end.
)

f^:_ >: i.3014387

----- Original Message -----
From: David Lambert <[email protected]>
To: programming <[email protected]>
Sent: Monday, December 19, 2016 2:06 PM
Subject: [Jprogramming] AoC 2016 day 19

Finally found a good answer.  http://oeis.org/A006257   Part 1:

white_elephant=: 1&|.&.#:

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

Reply via email to