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.
Back to the familiar, if somewhat finicky, realm of substring parsing to play a macro free game for part I. Like the answer to the question of Life, the Universe and Everything, part II will require Deep Thought.
Part I Part II requires a generic recursive algorithm that would be fairly easy in a traditional programming language, but is complex(for me at least) to implement in Alteryx. I have a inkling of how I could accomplish it, involving keeping track of parents and recursion level, but I won't be able to flush it out completely today
Part II rules are surprisingly simple, provided you read them well (including: ...(the quantity of cards copied is equal to the number on the card they drew to trigger the sub-game)... and ..(again so that the winner's card is above the other card)... ) I missed them for a while and spent a long time trying to understand why the macro was not working...
Part II now works with the "sample" dataset. But 100 000 iterations later it has not reached the end for the real input, which makes me think there may be something wrong with the macro, or, it's going to take a looong while to get it there.
The input is converted into: Deeper levels of recursion are kept as additional rows: It's awfully inefficient and the workflow is utterly cluttered right now. But not sure how much gain would be obtained from cleaning it properly. Alternatively, it may be worth rethinking the strategy altogether 😅
Took a bit longer than I would have liked to solve part 1 with first an error of mixing numbers and strings so not getting the desired output in the example dataset, and then when running the full dataset being out by one which was just to do with how I dealt the last cards in the pack, but managed to fix it.
It's nice being back into it as I just didn't really have the time last week to participate.
My approach for Part 2 is to turn the recursion into iteration and use generate rows. - I encode the 1-50 as ASCII characters (value plus 48 so 1=1, 2=2,...9=9,10=:,...) - First 2 words of the string are state if player 1 and 2 in the current game (or subgame) - After word 2, the previous state of the current game is stored as (P1#P2) separated by spaces - This is checked to see if P1 wins the game, if so the current game is ended and the change made to parent game (or iteration terminates) and current game is removed (replace up to first ` ! `) - Otherwise, if need to recurse then a new pair of P1 and P2 are added followed by a ` ! ` which marks the end of the current game state - If someone wins a game as other player runs out, then as above with P1 happens - If someone wins a round then the state is added to list and word 1 and word 2 are manipulated to be the new value
Doing some cleaning up I realized I didn't post my final approach. It did take a looong time
While I was building the iterative macro, I thought that a lot of the steps were just moving data from one place to another and it was all just a big "if else" statement. @jdunkerley79 's generate rows proves that was right, but I was not able to come up with a solution like that. Quite impressive.