IdeaMonk

thoughts, ideas, code and other things...

Wednesday, June 18, 2008

Scoring High in Word Games on facebook!



Ever played TextTwirl or WordShuffle on facebook or elsewhere ?

Don't you ever! for they are very addictive as my uber player buddy from Wisconsin warns me. But what can I do, I have my own problems, I'm jobless, there's nothing to do, And I like winning the smart way.
So, what do I do! I think of C++ and a Dictionary... and poof! my weapon is ready in my mind! And soon I come up with my own little tool called WordWar.
Heres the code:
  1. #include <iostream>  
  2. using namespace std;  
  3.   
  4. int main(int argc, char *argv[]){  
  5. string word,check,cword;  
  6. int len,match,count,checksum=0,l;  
  7.   
  8. if (argc>=3){  
  9.    word = argv[1];  
  10.    len = word.length();  
  11.    for (int i=0;i<len;i++)  
  12.      checksum+=word[i];   
  13.   
  14.    freopen (argv[2],"r+",stdin);  
  15.    if (argc==4){  
  16.      while (cin >> check){  
  17.        check[0]=tolower(check[0]);  
  18.       if (check.length()<=len &amp;&amp; check.length()>=3){  
  19.            match = 1;  count=0;  
  20.            cword=word;  
  21.                for (int i=0;i<check.length();i++){  
  22.                    if (cword.find(check[i]) == string::npos){  
  23.                       match=0;  
  24.                       break;  
  25.                    } else {  
  26.                       cword[cword.find(check[i])]='_';  
  27.                    }  
  28.                }  
  29.                if (match == 1)  
  30.                    cout << check << endl;  
  31.        }  
  32.        }  
  33.    } else {  
  34.    while (cin >> check){  
  35.        if (check.length()==len){  
  36.            match = 1;  count=0;  
  37.            for (int i=0;i<len;i++){  
  38.                if (word.find(check[i]) == string::npos){  
  39.                    match=0;  
  40.                    break;  
  41.                } else {  
  42.                   count+=check[i];  
  43.                }  
  44.            }  
  45.            if (match == 1 &amp;&amp; count==checksum)  
  46.                cout << check << endl;  
  47.        }  
  48.    }  
  49.  }  
  50. else {  
  51.    cout << "WordWar v0.1\t\t\t(c) Abhishek Mishra\n"  
  52.                <<"            \t\t\t ideamonk@gmail.com\n\n"  
  53.          <<"Usage : "<<argv[0]<<"> <dictionary_file>\n\n";  
  54. }  
  55. return 0;  
  56. }  

For this you also need a dictionary. Download dictionary here. This is a very basic dictionary, I recommend you to get better one or try adding 's' etc to this ones results. Compile WordWar in DevCPP/MinGW32 on windows or GCC on linux. Have 1.txt (your dictionary) in the same path. and run it like this ->

enjoy scoring high!
With PHP I can also make a neat live web interface to cheat. :)
happy hacking.
http://ideamonk.googlepages.com/ddl.gif

Labels: , ,

3 Comments:

At June 20, 2008 at 8:18 PM , Anonymous Anonymous said...

nice proggy, apart from spoj try being active on topcoder too, in TC you've to keep a track of ongoing srms.
nice blog.

 
At June 20, 2008 at 8:27 PM , Blogger Abhishek Mishra said...

thanks buddy. Yep i'll catchup with TC asap.

 
At November 10, 2008 at 3:32 PM , Anonymous Anonymous said...

Hey there! nice work. I had great fun setting high scores when I was bored.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home