(TL; DR) No improvement in performance despite using unique key dictionary i.e (`u#())!() .. but similar algorithm in python was giving results much much faster. Wondering if I had took a wrong approach in solving the problem
Q) https://adventofcode.com/2020/day/15
A) the algorithm i was trying to implement: https://np.reddit.com/r/adventofcode/comments/kdf85p/2020_day_15_solutions/gfwrwx6/
so we have to keep on appending numbers to the initial list (example 0 3 6) on the following conditions:
1) if last element of the unappended list has already occured (i.e not new) then append 0
2) else append the diiference between the current index and the index of last occurence
Eventually the list goes like this
0 3 6 0 3 3 1 0 4 0 ...
the questions asked were to find 2020th, 30000000th elements of such list
My initial solution:
________________
x: 13 0 10 12 1 5
f: {$[1 = count ind: where x = last x; x, 0; x, last deltas -2#ind]}
last (2020 - count x) f/ x
________________
it was slow for the second part (30000000th). so I used a hash map to store last occurrence
https://github.com/8wgf3b/letsee/blob/master/aoc2020/15.q
the problem was that there was no significant improvement in performance.
What do you guys suggest?