Calling all Racers for the Alteryx Grand Prix! It's time to rev your engines and race to the stage at Inspire! Sign up here.
alteryx Community

# General Discussions

Discuss any topics that are not product-specific here.

## Advent of Code 2022 Day 9 (BaseA Style)

Alteryx Community Team
19 REPLIES 19
8 - Asteroid

So many possible mistakes with hardcoding P2. Eventually got there but had the idea right early.

Spoiler

9 - Comet
Spoiler

There is a lot of if's for part 1, quite a bit testing to get it right as each line all look so alike.

Part 2 turns out to be easy with an iterative macro on part 1.

5 - Atom
Spoiler
My Approach for day 9 !

15 - Aurora

My solution to part 2 is brute force ugliness (but runs quickly). Pretty happy with my formula to determine tail position for part 1.

Spoiler
First attempt was to calculate the X and Y coordinates of the tail in separate steps. That didn't work with my logic. So here is the not-so-ugly formula for the Multirow -

IF IsEmpty([Row-1:Field1]) THEN [Position_T] ELSEIF Abs([X_H]-tonumber(left([Row-1:Position_T],findstring([Row-1:Position_T],","))))<=1 AND
ABS([Y_H]-tonumber(right([Row-1:Position_T],findstring(reversestring([Row-1:Position_T]),","))))<=1 THEN
[Row-1:Position_T]
ELSE tostring([Row-1:X_H])+","+tostring([Row-1:Y_H])
ENDIF
15 - Aurora

Now that I've gotten over my trauma and shock over my horrible solution, I'd like to add this one as well.

Spoiler

Macro part 1:

As it followed the wrong approach... I had to do something different for part 2 ... and it's a mess.

17 - Castor

This was not an easy one - made even tougher by the fact that I didn't read the original instructions in part 1 properly but the issue was obscured until I started to move stuff round in part 2.

Spoiler
This solution has several parts:

Part 1: clean up the moves to only work in 1 step moves:

This just takes multiple step moves, and turns them into a series of one-step moves

Part 2: Do the magic bit and count the results

The magic bit: Part 1:
This is an iterative macro - which iterates over the moves, and uses a YXDB to also pass the position to each new iteration

Within this there are 2 sub-macros:
The logic of moving the header is different than moving the tailing nodes - so it's split into two different macros.

And then moving the tailing nodes is also an iterative macro:

The magic part is the move formula for the trailing item:

That was a long couple of days :-)

12 - Quasar

I know this is ugly, but at least it passed.

Spoiler
Main

Macro

Formula in the macro:

``````IF IsEmpty([Row-1:tail_xy]) THEN "0,0" // 初期値

ELSEIF
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) ) <= 1
AND
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) ) <= 1
THEN [Row-1:tail_xy]

= REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")
> ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) + 1
THEN
+ ","
+ ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) + 1)

= REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")
< ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) - 1
THEN
+ ","
+ ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) - 1)

= REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")
> ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) + 1
THEN
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) + 1)
+ ","

= REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")
< ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) - 1
THEN
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) - 1)
+ ","

ELSEIF
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) >= 1
AND
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) >= 1
THEN
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) + 1)
+ "," +
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) + 1)

ELSEIF
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) >= 1
AND
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) <= -1
THEN
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) + 1)
+ "," +
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) - 1)

ELSEIF
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) <= -1
AND
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) >= 1
THEN
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) - 1)
+ "," +
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) + 1)

ELSEIF
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) <= -1
AND
- ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) <= -1
THEN
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$1")) - 1)
+ "," +
ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "\$2")) - 1)

ELSE [Row-1:tail_xy]
ENDIF``````

13 - Pulsar
Spoiler

17 - Castor

Finally got time to catch up on a couple of days and finished off 9!

Spoiler

Iterative macro - turns each knot into the new head:

Alteryx Product Evangelist