Otherwise, I've solved all with j.

--- Day 18: Operation Order ---

Part 2:

Operator overloading usually doesn't include precedence alterations.  I abandoned j and used python.  Swapping operators and wrapping the numbers with a class that evaluates + as * (and multiplies for +), I evaluated strings rewritten from '1 + 2 * 3' to 'screwy(1) * screwy(2) + screwy(3)' .

class screwy:
    def __init__(a, b): a.a = b
    __add__= lambda a,b: screwy(a.a * b.a)
    __mul__= lambda a,b: screwy(a.a + b.a)

print(eval('screwy(1) * screwy(2) + screwy(3)').a)



--- Day 15: Rambunctious Recitation ---

Part 2:

My j solution already appears in the programming forum as sparse array trouble.  (IIRC) Some years ago Roger had asked for sparse array problem reports, which must be so because he responded. Anyway, my formulation was slow in j so I translated it to c.  The sparse array needn't be sparse, and that code runs the thirty million test case in 37 seconds on the high end processor option at the time Thinkpad W540.

For 2020 player turns the program with sparse array runs 5 times slower than a dense array version.   With a sparse table I'm unwilling to wait for timing results of the thirty million loops.


Today it looks like we're to construct a regular expression from an hideous tree.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to