Erm yeah,
After a bit of research I realised using a permutation generator to solve anagrams is a waste of time! Much better is to use a letter frequency counter and then to compare this with the letter frequency count of words within a dictionary file.
To illustrate, say I have the word : a,t,r,s
in its jumbled form. Now I count the number of times each alphabet occurs. So:
Code:
a=1, t=1, r=1, s=1:
Now I do the same for every word in the dictionary file and output matches to the screen.
In this case the dictionary would find two matches, *star* and rats*
since both words have the same *LETTER FREQUENCY COUNT*. As it turns out, this method to solve anagrams is incredibly quick!
Moreoever, on a completely different note, I have hypothesised that the same method can be used to identify terms of an algebraic expression. For example I could use it to identify which terms I need collect and then add the coefficients.
Code:
=5xcv+8xvc+7nm
= 13xcv+7nm
So getting back to this anagram solver. OK. First you will need a dictionary file. Go to the following web address, select all and save it in a notepad file. Name that file 'dictionary.txt'. Make sure this file is in your Dev++ folder.
http://www.newlife4square.org/progs/words.lex
Great. Now copy and paste this code into your program and you're done.
Code:
#include <iostream>
#include<string.h>
#include<fstream>
using namespace std;
int main()
{fstream file_pointer_in;fstream file_pointer_out;
file_pointer_in.open("dictionary.txt",ios::in);
file_pointer_out.open("treenef.txt",ios::out);
int a,b;char array[81];cout<<"Plz nta ur word:"<<endl;
cin>>array;cout<<"Hacking..Your system...cough.cough"<<endl;
cout<<" "<<endl;cout<<" "<<endl;int mass;mass = strlen(array);
char alphabet[28]={"/abcdefghijklmnopqrstuvwxyz"};
int alphacount[26];int betacount[26];
for (int i=1; i<27; i++){ alphacount[i]=0;}
for(a=0; a<mass; a++){for(int j=1; j<27; j++)
{if (array[a]==alphabet[j]){alphacount[j]++; }}}
char x[81];do{file_pointer_in>>x;int size;
size = strlen(x);for (int i=1; i<27; i++)
{betacount[i]=0;}for (int i=0; i<size; i++)
{for (int j=1; j<27; j++){if (x[i]==alphabet[j]){betacount[j]++;}}}
int counter=0;int treenef=0;for (int k=1; k<27; k++)
{if (betacount[k]==alphacount[k]){treenef++;}
if (betacount[k]<=alphacount[k]){ counter++;}}if (treenef==26)
{file_pointer_out<<"** BINGO ***:"<<x<<endl;cout<<x<<endl;}
if (counter==26){file_pointer_out<<x<<endl;}}
while(file_pointer_in.peek()!=EOF);cout<<"Quilt (y/n)";
int stop;cin>>stop;
file_pointer_in.close();file_pointer_out.close();}
Lol I love that syntax don't you?