Another way to approach this problem first part, which was refined by
Jimmy's
elegant solution, follows.

Start by finding all the ne's and sw's in the list. To the extent the 2
counts are equal,
they cancel one another, and similarly with the nw and se pairs. (So we can
pretend
that any such matching pairs cancel out one another and can be ignored from
further
analysis.)

The excess from these 2 comparisons must produce all nw's and sw's or all
ne's and se's
because all of the pairs that were cancelled eliminate the other
possibilities:
ne's and se's are impossible in the first case; nw's and sw's, in the
second case.
Call the remaining (that is the non-zero) steps nx's and sx's,
where the x's can be either e's or w's (we are indifferent). All we care
about now
is whether the the number of nx's is greater than the number of sx's, or
vice versa.

If the nx's exceed the sx's by an amount, call the amount mn, (more n's).
If the sx's exceed the nx's by an amount, call the amount ms, (more s's).

If we have mn and the plain n's exceed the plain s's by N, then the total
steps is N+mn.
If we have ms and the plain s's exceed the plain n's by S, then the total
steps is S+ms.

If we have mn but the plain s's exceed the plain n's by S, then the total
steps is |S-mm.
If we have ms but the plain n's exceed the plain s's by N, then the total
steps is |N-ms.



On Mon, Dec 11, 2017 at 3:54 PM, Jimmy Gauvin <[email protected]>
wrote:

> Hi,
>
> I used axial coordinates from https://www.redblobgames.com/grids/hexagons/
> to get thru part 1.
> Will do part 2 tonite.
>
>    >./ | +/hxv {~ dbd i. <;._1 ',', dbi
> 675
>
> where :
>
>    dbi=: }: fread 'C:\Downloads\day11inp'
>    dbd=: ;:'n s ne nw se sw'
>    hxv =: 6 2 $ 0 _1 0 1 1 _1 _1 0 1 0 _1 1
>    dbd,.<"1 hxv
> ┌──┬────┐
> │n │0 _1│
> ├──┼────┤
> │s │0 1 │
> ├──┼────┤
> │ne│1 _1│
> ├──┼────┤
> │nw│_1 0│
> ├──┼────┤
> │se│1 0 │
> ├──┼────┤
> │sw│_1 1│
> └──┴────┘
>
>
>   \ n  /
> nw +--+ ne
>   /    \
> -+      +-
>   \    /
> sw +--+ se
>   / s  \
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to