module vbagram ' vbagram.bas -- Find anagrams ' Written August 8, 2019 by Eric Olson ' Based on anagram-sb.bas written by John Spikowski ' ' This program demonstrates using associative arrays and a bubble ' sort to find anagrams in the insane British dictionary. dim filename, wordlist() as string function isword(s as string) as boolean dim i,c as integer for i=1 to len(s) c=asc(mid(s,i,1)) if (casc("z")) then return false end if next i return true end function function strkey(s as string) as string dim sortword as string dim i,j as integer sortword=s for i=1 to len(sortword) for j=i+1 to len(sortword) if mid(sortword,i,1)>mid(sortword,j,1) then dim temp as string temp=mid(sortword,i,1) mid(sortword,i,1)=mid(sortword,j,1) mid(sortword,j,1)=temp end if next j next i return sortword end function dim anagram as new system.collections.generic.dictionary(of string,string) dim index as new system.collections.generic.list(of string) function main() as integer dim thisword,sortword as string filename="/usr/share/dict/british-english-insane" wordlist=system.io.file.readalllines(filename) for each thisword in wordlist if isword(thisword) then sortword=strkey(thisword) if anagram.containskey(sortword) then dim temp as string anagram.trygetvalue(sortword,temp) anagram.remove(sortword) anagram.add(sortword,temp+" "+thisword+",") else anagram.add(sortword,thisword+":") index.add(sortword) end if end if next thisword dim anaidx as string for each anaidx in index dim temp as string anagram.trygetvalue(anaidx,temp) if right(temp,1)="," then console.writeline(left(temp,len(temp)-1)) end if next anaidx end function end module