13 October 2006

TextTwist Solver

Posted under: at 00:10

TextTwist

Among all kinds of time wasters out there, word games got to be my favorite. And from all those word games, there’s one game that stands out from the other, it’s called TextTwist. It is a very simple word game, and yet very addictive. I know I’m not alone, the game is consistently placed as one of the most popular game for months, maybe years, while the likes of Dynomite, Bejeweled and now Zuma tend to be short lived craze.

The game presents a set of six letters and the player needs to arrange the letters to form English words from three to six letters long within the allotted time. If the player can find at least one six letter word, it advances to the next puzzle. Otherwise, the game is over. The player get extra score for every words found, and a big bonus if all words were found before the time runs out.

The love for a game time waster is not complete before you write a cheat solver for it. So, despite the abundance of the exact same solver on the net, I wrote mine below. It is in Perl, so you will need (obviously) a Perl interpreter. You also need Aspell with English dictionary installed.

#!/usr/bin/perl

open(ASPELL, 'aspell dump master en|');
while(<ASPELL>) {
   chomp;
   $_ = lc $_;
   next unless /^[a-z]{3,6}$/;
   if (check($_, $ARGV[0])) {
      push @out, $_;
   }
}
print join("\n", sort {length $a <=> length $b || $a cmp $b} @out);
print "\n";

sub check {
   ($word, $letters) = @_;
   %letcount = ();
   foreach (split(//, $letters)) {
      $letcount{$_}++;
   }
   foreach (split(//, $word)) {
      $letcount{$_}--;
      return if $letcount{$_} < 0;
   }
   return 1;
}

Save the code as texttwist.pl and run it like ./texttwist.pl lorstl where ‘lorstl’ is the letters presented in the game.

Needless to be said, this post also serves as a “never trust high score list unless you see the game yourself” kind of warning. However, I used to consistently score above 150000 with my Palm version, with high score between 500000 and 600000, without any cheats, honest!

Obligatory links:

51 Responses

Trackback: Use this URI to trackback this entry. Use your web browser's function to copy it to your blog posting.

Comment RSS: You can track conversation in this page by using this page's Comments RSS (XML)

Gravatar: You can have a picture next to each of your comments by getting a Gravatar.

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Warning: Comments carrying links to questionable sites will be removed!