solver.js
// By far, the most compute-intensive function
By far, the most compute-intensive function
By far the most compute - intensive function
function nextSolutions(solutions) {
			let nextSolutions = {}
			for (let sol = 0 ; sol < solutions.length ; sol++) {
				let solCanon =  solutions[sol].canonical
				let maxLength = numOfBlocks - solCanon.length
				for (let wrd = 0 ; wrd < wordList.length ; wrd ++) {
					let wrdCanon = wordList[wrd].canonical
					if (wrdCanon.length > maxLength) {
						continue
					}
					let combined = canonicalVersion(solCanon + wrdCanon)
					if (canWorkFast(combined)) {
						addToSolutionSet(nextSolutions, combined, solutions[sol], wrdCanon)
					}
				}
			}
			let result = []
			for (let solution in nextSolutions) {
				result.push({
					canonical: solution,
					factors: nextSolutions[solution]
				})
			}
			return result
		}
function nextSolutions ( solutions ) { let nextSolutions = { } for ( let sol = 0 ; sol < solutions . length ; sol ++ ) { let solCanon = solutions [ sol ] . canonical let maxLength = numOfBlocks - solCanon . length for ( let wrd = 0 ; wrd < wordList . length ; wrd ++ ) { let wrdCanon = wordList [ wrd ] . canonical if ( wrdCanon . length > maxLength ) { continue } let combined = canonicalVersion ( solCanon + wrdCanon ) if ( canWorkFast ( combined ) ) { addToSolutionSet ( nextSolutions , combined , solutions [ sol ] , wrdCanon ) } } } let result = [ ] for ( let solution in nextSolutions ) { result . push ( { canonical : solution , factors : nextSolutions [ solution ] } ) } return result }
By far, the most compute-intensive function
By far the most compute - intensive function
// For every solution, try combining it with every word // This double loop is the bottleneck of the entire algorithm // Some optimization - a length check is faster than canWorkFast(canonicalVersion(solCanon + wrdCanon)) // Convert back to list