Countdown Letters ME

Impressed by the abilities of my new mobile phone - the K750i is actually now rather old by mobile phone standards - I thought I'd see what I could do with J2ME (that's Java for mobile phones). Thus was born the Countdown letters game solver. You enter the letters as they are read out by Carol, hit solve and in no time your phone will tell you the 5 best words you can get with those letters (and without connecting to the internet, all the data is on the phone). It takes about 10 seconds on my phone, newer phones would probably be even quicker.

You can download the JAR and JAD files at the bottom of this page. I don't know about other phones, but the way you install them on my phone is:

  1. Download the JAR file to your computer
  2. Copy the file to the mediafiles/other folder on the phone
  3. Go to the Other folder in the File Manager and click Install.
  4. Install to Applications or Games as you see fit.
  5. Run it, it's obvious how you use it.

Technical notesĀ 

I've also included the source code Java file below (rename it from .java.txt to .java) for anyone who might be interested.

I used the following code to create the dict.dat file, with the longest words (9 letters) first, and then the shorter words. This is standard Java, not for the mobile phone. The file words-small.txt was made from the SCOWL word list on Kevin's Word List page by selecting only the English and British words and variations, not including the 80 and 95 lists (of very obscure words) to keep the file size down. On unix, you can do this quickly by putting all the lists you want to include in a specific directory, going to that directory and running cat * >../words.txt.

try {
// output datastream only opened once
File file= new File("words-small.dat");
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos=new DataOutputStream(fos);
String str;
// for each word length, find all valid words of that length
for(int i=9;i>=1;i--){
BufferedReader in = new BufferedReader(new FileReader("words-small.txt"));
while ((str = in.readLine()) != null) {
// is it the right length?
// is it valid?
boolean v=true;
for(int j=0;j<str.length();j++){
if(str.charAt(j)<'a' || str.charAt(j)>'z') v=false;
if(v) dos.writeUTF(str);
} catch (IOException e) {}

Using Java DataStream files is a very efficient way to read a JAR resource file on a mobile phone, much better than reading it byte by byte and parsing into strings. The code to then find the words is basically as follows (although see the full source at the bottom of this page if you want to get it running):

InputStream is = getClass().getResourceAsStream("/dict.dat");
if (is == null)
throw new Exception("File Does Not Exist");
DataInputStream dis = new DataInputStream(is);

int foundwords=0;
stringItemSolution.setText(""); // start off with no found words, we add to this text display
while(dis.available()>0 && foundwords<5){
String s = dis.readUTF(); // read the next word from the dictionary file
StringBuffer lb = new StringBuffer(l); // an editable copy of the letters available
// can we make the string s using the letters available?
boolean makeable=true;
for(int i=0;i<s.length() && makeable;i++){
String sc = s.substring(i,i+1); // the ith letter in the word we're checking
int j=lb.toString().indexOf(sc); // the index of this letter in the letters still available
lb.setCharAt(j,' '); // set the letter to ' ' to indicate it's been used up
} else {
makeable=false; // j=-1 means the letter we were looking for is not there so we can't make it
// we can make this word
stringItemSolution.setText(s); // add to the list
} else {
stringItemSolution.setText(stringItemSolution.getText()+'\n'+s); // add to the list


countdownlettersme.jar290.26 KB
countdownlettersme.jad398 bytes
letters.java.txt9.24 KB