Last active
April 5, 2022 19:38
-
-
Save keksipurkki/9d0bc20c013dad7206bdb5d46148d0b9 to your computer and use it in GitHub Desktop.
Solve http://www.playtypeshift.com like a pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const cartesian = (...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat()))); | |
const intersection = (a, b) => new Set([...a].filter((x) => b.has(x))); | |
const letters = [ | |
["n", "h", "i", "m", "w"], | |
["a", "h", "y", "i", "m"], | |
["c", "b", "x", "o", "l"], | |
["k", "o", "i", "u"], | |
["e", "s", "n"], | |
["g", "y", "h", "s", "d"], | |
]; | |
function dictionary() { | |
const str = fs.readFileSync("/usr/share/dict/words").toString(); | |
const words = str.split("\n").filter(Boolean); | |
return new Set(words); | |
} | |
function trials(letters) { | |
const words = [...cartesian(...letters)].map((x) => x.join("")); | |
return new Set(words); | |
} | |
function main() { | |
try { | |
console.log(intersection(dictionary(), trials(letters))); | |
} catch (e) { | |
console.error(e); | |
process.exit(1); | |
} | |
} | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set(9) { | |
'hacked', | |
'hickey', | |
'macies', | |
'nibong', | |
'nickey', | |
'waling', | |
'waxing', | |
'whoosh', | |
'wicked' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment