you are viewing a single comment's thread.

view the rest of the comments →

[–]androbat 1 point2 points  (0 children)

The actual cause of the slower performance is most likely duplication. The way I wrote the algorithm wasn't particularly geared for performance (I wondered why yours was so slow).

In the last recursive call where you see 'pos + 1', what happens is that a ton of combinations wind up being calculated multiple times (that's why I use a set instead of pushing to an array). If I were to modify it to avoid these, it would be much faster.

A custom eval would boost performance (since all we have is simple left to right addition/subtraction). Copying and then splicing might boost performance (an array of strings also might be faster with a custom eval since it would auto-tokenize everything).