Pig Latin is a word game where words are modified according to some rules:
Now, call a word interesting if its Pig Latin form is still an English word; for example, the Pig Latin of "trash" is "ashtray". It is easy to see that words with no vowels are trivially interesting. We do not want to take such words into account.
Here is a list of about 45 thousand words. Assuming that these are all the valid English words, find the number of non-trivial , interesting words.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
A simple function to check this property is easy to write:
Which can be improved my making it a generator, or using a regex potentially. The real challenge is that you need to check if the output is also a word. Since the lists are so long, a worthwhile effort is to optimize this part of the problem. The traditional approach is to use a Trie.
Thus, encode the list of words in a trie, and then just loop over keys in the trie with the above function, and test if they're in the trie, and not trivial.
As with many of these kinds of problems, this depends a lot on the dictionary. I like a larger dictionary, so in addition to the svelte one provided, I ran the program on a bigger dictionary. The result is more fun:
[('ab', 'abay'), ('abac', 'abacay'), ('abr', 'abray'), ('ad', 'aday'), ('al', 'alay'), ('ald', 'alday'), ('all', 'allay'), ('alw', 'alway'), ('am', 'amay'), ('amb', 'ambay'), ('amir', 'amiray'), ('an', 'anay'), ('ap', 'apay'), ('app', 'appay'), ('arr', 'array'), ('ass', 'assay'), ('ast', 'astay'), ('astr', 'astray'), ('aw', 'away'), ('ba', 'abay'), ('bam', 'ambay'), ('bes', 'esbay'), ('bra', 'abray'), ('bun', 'unbay'), ('caba', 'abacay'), ('da', 'aday'), ('dal', 'alday'), ('enl', 'enlay'), ('ess', 'essay'), ('fo', 'ofay'), ('fra', 'afray'), ('isl', 'islay'), ('ko', 'okay'), ('la', 'alay'), ('lad', 'adlay'), ('lavant', 'avantlay'), ('len', 'enlay'), ('lin', 'inlay'), ('linter', 'interlay'), ('lis', 'islay'), ('lout', 'outlay'), ('lover', 'overlay'), ('ma', 'amay'), ('na', 'anay'), ('oath', 'oathay'), ('of', 'ofay'), ('ok', 'okay'), ('outr', 'outray'), ('outs', 'outsay'), ('overs', 'oversay'), ('pa', 'apay'), ('pap', 'appay'), ('plout', 'outplay'), ('plover', 'overplay'), ('plu', 'uplay'), ('plunder', 'underplay'), ('pout', 'outpay'), ('ppa', 'appay'), ('prover', 'overpray'), ('pun', 'unpay'), ('rab', 'abray'), ('raff', 'affray'), ('rami', 'amiray'), ('ren', 'enray'), ('rest', 'estray'), ('riv', 'ivray'), ('rout', 'outray'), ('run', 'unray'), ('sta', 'astay'), ('stout', 'outstay'), ('stover', 'overstay'), ('stra', 'astray'), ('stre', 'estray'), ('sun', 'unsay'), ('sunder', 'undersay'), ('swa', 'asway'), ('tas', 'astay'), ('touts', 'outstay'), ('trash', 'ashtray'), ('tres', 'estray'), ('tups', 'upstay'), ('unb', 'unbay'), ('unl', 'unlay'), ('unp', 'unpay'), ('uns', 'unsay'), ('wa', 'away'), ('wair', 'airway'), ('wany', 'anyway'), ('warch', 'archway'), ('was', 'asway'), ('wedge', 'edgeway'), ('wup', 'upway')]