it works, and it's faster than i expected but obviously still can't traverse the entire search space for large inputs
the hard part looks to be coming up with not just a heuristic for the purpose of searching more efficiently, but also for rating the output anagrams, which are extremely numerous
i was thinking perhaps i'd have an interface similar to this where users can fix certain words in place to narrow the search. but the great difficulty i had using that to find a good anagram makes me question how useful it will be here
perhaps it could be augmented by showing the number of solutions found so far if you were to fix a certain word. it would be cool and probably quite possible to have it be 'live' also and update as more solutions are found
this exercise taught me that you can't just magically optimise for something unless you can clearly define what it is. it's unclear what exactly makes an anagram 'good', not easy to tell if a sentence is comprehensible and hard to guess
i tried using both word length and word frequency to make a search heuristic, but i can't tell whether or not it helped because there are so many solutions. i saw no reason to bother with letter distribution because i had no shortage of valid anagrams
maybe next i'll try specifically avoiding short words, rather than just scoring better for longer words but not really penalising 6+1+1+1 vs 6+3
one trick i used was ensuring each prospective sentence was always lexicographically sorted to cut down on permutations of existing sentences e.g. 5! different orderings for every sentence with 5 words
however, overall i think it's likely the performance is far from optimal because javascript and i did a fair amount of string manipulation and generally didn't consider performance details that much while writing code, but i think it performs well enough
i got it working with a web worker which stops the browser from hanging, originally i thought there was a memory issue inherent to the problem but it was just a dumb bug that created a lot of unnecessary objects
since i wanted to allow the solver to be paused and send live updates to the page reporting partial results, i had to hardcode a number of iterations that the worker algorithm does before waiting for the next 'frame' which calls setInterval with no delay
i also wanted to use a binary tree and couldn't be bothered writing my own implementation so i decided to install one from npm and make it into a node project (i know, hear me out)
i figured out how to use webpack so it generates static javascript files instead of using node as a backend or whatever it usually does. it's kind of nice how you can import random data files and it bundles it with the script
it did make me feel gross afterwards, but i tell myself it isn't so bad so long as the output is static javascript. i can still make my own html template so it's not some gross poorly performant dom-munging thing, which is honestly the main gripe i have with modern web development
i think i looked down on using npm before understood how webpack worked, because i assumed i'd have to serve it with node and i saw a lot of packages had bought into this. i guess it does allow me easy access to a lot of javascript libraries without having to directly link or copy over the scripts, which is undeniably valuable
i didn't even end up using binary trees yet and might not bother, but i'm glad i learned some things
i'll post it here after i've polished it further, at some date that is not right now