Skip to content

Instantly share code, notes, and snippets.

@Windows81
Last active April 6, 2021 05:25
Show Gist options
  • Select an option

  • Save Windows81/3137f8d1b59504fab65a7a2c2da9570d to your computer and use it in GitHub Desktop.

Select an option

Save Windows81/3137f8d1b59504fab65a7a2c2da9570d to your computer and use it in GitHub Desktop.
Run this on your web browser on the Corncob page (http://www.mieliestronk.com/corncob_lowercase.txt) to get a list of anagrams for the word 'Undertale'.
//Enter text string here.
s='undertale'
let d={}
let l=s.length
for(let c of s.split(''))d[c]=~~d[c]+1
let w=document.body.innerText.split('\n').map(v=>{
a={}
let i=0
for(let c of v.split(''))
if(!d[c])return
else a[c]=~~a[c]+1,i++
return[v,i,a]
}).filter(v=>v)
function f(d,l,s){
if(!l)return[[]]
else if(l<0)return[]
let t=[]
for(let[v,i,a]of w){
if(!i)continue
let h={}
for(let i in d)
if(!h)break
else if((h[i]=d[i]-~~a[i])<0)h=null
if(h)
for(let b of f(h,l-i,v))
t.push([v,...b])
}
return t
}
let r=f(d,l,s)
console.log(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment