This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
So many possible mistakes with hardcoding P2. Eventually got there but had the idea right early.
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.
My solution to part 2 is brute force ugliness (but runs quickly). Pretty happy with my formula to determine tail position for part 1.
Now that I've gotten over my trauma and shock over my horrible solution, I'd like to add this one as well.
Macro part 1:
As it followed the wrong approach... I had to do something different for part 2 ... and it's a mess.
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.
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:
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:
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 :-)
I know this is ugly, but at least it passed.
Macro
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
Finally got time to catch up on a couple of days and finished off 9!
Iterative macro - turns each knot into the new head:
Can you share this excel file? Really great example @grossal !