Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2022 Day 9 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Discussion thread for day 9 of the Advent of Code - https://adventofcode.com/2022/day/9
19 REPLIES 19
mmontgomery
10 - Fireball

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

Spoiler
mmontgomery_0-1670618625702.pngmmontgomery_2-1670618660137.png

 

mmontgomery_1-1670618647866.png

 

 

LiuZhang
9 - Comet
Spoiler
Day 9 - 1 - Workflow.pngDay 9 - 2 - Macro.png

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.

ApekshaSharma
6 - Meteoroid
Spoiler
My Approach for day 9 !

Day 9.PNG

estherb47
15 - Aurora
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
grossal
15 - Aurora
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
grossal_0-1670758787016.png

 


Macro part 1:

grossal_1-1670758817793.png


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

grossal_2-1670758854796.pnggrossal_3-1670758883802.png

 

SeanAdams
17 - Castor
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:
SeanAdams_0-1670816319630.png

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

SeanAdams_1-1670816358098.png


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

SeanAdams_2-1670816459905.png


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

Move Header:

SeanAdams_3-1670816558267.png

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

SeanAdams_4-1670816615067.png

 


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

SeanAdams_7-1670816722953.png

 




SeanAdams_5-1670816665122.pngSeanAdams_6-1670816687259.png

 


That was a long couple of days :-) 

Yoshiro_Fujimori
15 - Aurora

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

Spoiler
Main
Yoshiro_Fujimori_0-1670893000699.png

Macro

Yoshiro_Fujimori_1-1670893051168.png

Formula in the macro:

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

// headがtailと隣接 -> 動かない
ELSEIF
  ABS(  ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
      - ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) ) <= 1
  AND  
  ABS(  ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
      - ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")) ) <= 1
THEN [Row-1:tail_xy]

// headがtailの上方 -> 上へ1
ELSEIF REGEX_Replace([head_xy], "(.+),(.+)", "$1")
     = REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")
  AND  ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
     > ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")) + 1
THEN
  REGEX_Replace([head_xy], "(.+),(.+)", "$1")
  + ","
  + ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")) + 1) 

// headがtailの下方 -> 下へ1
ELSEIF REGEX_Replace([head_xy], "(.+),(.+)", "$1")
     = REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")
  AND  ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
     < ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")) - 1
THEN
  REGEX_Replace([head_xy], "(.+),(.+)", "$1")
  + ","
  + ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")) - 1) 

// headがtailの右方 -> 右へ1
ELSEIF REGEX_Replace([head_xy], "(.+),(.+)", "$2")
     = REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")
  AND  ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
     > ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) + 1
THEN
  ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) + 1)
  + "," 
  + REGEX_Replace([head_xy], "(.+),(.+)", "$2")

// headがtailの左方 -> 左へ1
ELSEIF REGEX_Replace([head_xy], "(.+),(.+)", "$2")
     = REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$2")
  AND  ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
     < ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) - 1
THEN
  ToString(ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) - 1)
  + "," 
  + REGEX_Replace([head_xy], "(.+),(.+)", "$2")

// headがtailの右上 -> 右上へ1
ELSEIF
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
  - ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) >= 1
  AND
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
  - 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)

// headがtailの右下 -> 右下へ1
ELSEIF
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
  - ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) >= 1
  AND
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
  - 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)

// headがtailの左上 -> 左上へ1
ELSEIF
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
  - ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) <= -1
  AND
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
  - 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)

// headがtailの左下 -> 左下へ1
ELSEIF
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$1"))
  - ToNumber(REGEX_Replace([Row-1:tail_xy], "(.+),(.+)", "$1")) <= -1
  AND
    ToNumber(REGEX_Replace([head_xy], "(.+),(.+)", "$2"))
  - 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

 

DaisukeTsuchiya
13 - Pulsar
Spoiler
DaisukeTsuchiya_0-1670943837154.png

 

DataNath
17 - Castor

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

 

Spoiler
DataNath_0-1671050273980.png


Iterative macro - turns each knot into the new head:

DataNath_1-1671050301377.png
JoshuaB
Alteryx Product Evangelist
Alteryx Product Evangelist

Can you share this excel file? Really great example @grossal !

Joshua Burkhow | Chief Evangelist @ Alteryx | Follow me on LinkedIn and Twitter
Labels