Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2020 - BaseA Style (Day 23)

Jean-Balteryx
16 - Nebula
16 - Nebula

Discussion thread for day 23 of the Advent of Code : https://adventofcode.com/2020/day/23

2 REPLIES 2
jdunkerley79
ACE Emeritus
ACE Emeritus

Not sure I have a clue how to do part 2 resorted to Python (the data structure needed is too hard in BaseA!)

 

Spoiler
Went for iterative macro for 1
jdunkerley79_0-1608716842655.png
jdunkerley79_1-1608716856372.png


Part 2 Python:

from ayx import Alteryx
import pandas as pd 
df = Alteryx.read("#1")
vals = list(df['V'])
l = len(vals)

class Cup:
    def __init__(self, v: int):
        self.v = v
        self.next = None
    
    def __repr__(self):
        return f'C({self.v}:{self.next.v})'

d = {}
for i, v in enumerate(vals):
    c = Cup(v)
    if i > 0:
        d[vals[i - 1]].next = c
        
    d[v] = c
d[vals[-1]].next = d[vals[0]]

current = d[vals[0]]

for i in range(df['games'][0]):
    c_next = current.next
    current.next = current.next.next.next.next
    pickup = [c_next.v, c_next.next.v, c_next.next.next.v]

    i = 1
    while (current.v - i if current.v - i > 0 else current.v - i + l) in pickup:
        i += 1
    i = (current.v - i if current.v - i > 0 else current.v - i + l)
    t_next = d[i].next
    d[i].next = c_next
    c_next.next.next.next = t_next
    
    current = current.next

current = d[1]
output = []
while (current.next.v != 1):
    output.append(current.v)
    current = current.next

df = pd.DataFrame(output)
Alteryx.write(df,1)

 

 

 

danilang
19 - Altair
19 - Altair

Part I as an iterative macro.  A single multirow would be massive because of the requirement to find the largest value smaller than the current one.  A large nested iif could do it with something on the range of 25 clauses comparing the 5 remaining values to each other.  This monster would be nested inside the outer part that rearranges the string.  Too... many... parentheses...

 

Part II hits the temporal limits of what can be done in BaseA.  Without arrays, there's no way to conveniently store 1M values other than in rows.  While it is possible to convert this algorithm from string based to row based and using filters and sorting to rearrange the items as required, iterating 10M times is not something that I'm prepared to wait for.

 

Spoiler
macro.png

Dan

Labels
Top Solution Authors