Over a million developers have joined DZone.

Google Code Jam Alien Language Solution

·
// Complete description of the problem and the code can found
// http://united-coders.com/christian-harms/google-code-jam-solution-for-alien-language


import sys, re
fp = file(sys.argv[1])
 
#read params
(l, d, n) = [int(x) for x in fp.next().split()]
 
#read words
words = [fp.next() for x in range(d)]
 
#read pattern
for i in range(1, n+1):
    searchStr = fp.next().replace("(","[").replace(")","]")
    searchIt = re.compile(searchStr).search
    print "Case #%d: %d" % (i, len(filter(searchIt, words)))
fp.close()
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}