Two Word Games
October 9, 2012
It’s been a while since we played word games. We have two today:
1) Find all the words in a dictionary that contain exactly five vowels (a, e, i, o and u) in ascending order.
2) Find all the words in a dictionary of length at least six that contain letters in strictly ascending alphabetical order.
These games are easy to play using regular expressions, so you should solve them without regular expressions, using only simple string manipulations. If your system doesn’t provide a dictionary, you can find one at http://icon.shef.ac.uk/Moby/mwords.html.
Your task is to play the two games. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
[…] today’s Programming Praxis exercise, our goal is to find all the words in a dictionary that satisfy two […]
My Haskell solution (see http://bonsaicode.wordpress.com/2012/10/09/programming-praxis-two-word-games/ for a version with comments):
public class WordGame1
{
public List Execute()
{
string line;
var results = new List();
var file = LoadFile();
while ((line = file.ReadLine()) != null)
{
if (ContainsAllFiveVowels(line))
results.Add(line);
}
return results;
}
private static StreamReader LoadFile()
{
var assembly = Assembly.GetExecutingAssembly();
return new StreamReader(assembly.GetManifestResourceStream(“ProgrammingPraxis.Content.354984si.ngl”));
}
private static bool ContainsAllFiveVowels(string textString)
{
return Vowels.All(vow => textString.IndexOf(vow, StringComparison.CurrentCultureIgnoreCase) >= 0);
}
private static IEnumerable Vowels
{
get { return new List {“a”, “e”, “i”, “o”, “u”}; }
}
}
[…] day, another post from Programming Praxis. Today they posted a word game that seems simple enough: first find all […]
That was fun. Most of the work went into loading the file and iterating through them line by line (I miss Python’s
for line in open(filename, 'r'):
), but the rest was pretty straight forward.My solution in Racket / Scheme
A Python solution:
OK, those are great. But of course you can take a low-tech approach to word games, like here: http://daisybrain.wordpress.com/2012/03/09/wordarchy/