I find that the best way to learn a new language is to start using it to solve simple everyday problems as often as possible. I recently finished a four-day Python programming course so I am now in a constant lookout for ways I could apply this cool language.
I found an interesting post on Alley Insider about a Microsoft puzzle used to interest students in working at Microsoft. As a student of Python, I figured I was game.
I read the rules literally and wrote a Python application to produce all the permutations of the data. Here is the resulting code:
results = []; def permutations(choices): for i in xrange(0,len(choices)): results.append( choices[i] ); nextchoices = [word for word in choices if word != choices[i]]; if len(nextchoices): permutations(nextchoices); results.pop(); else: chars = []; for x in xrange(0,4): for y in xrange(0,len(results)): chars.append(results[y][x]); print ''.join(chars); results.pop(); words = 'IOME HCRE REEC RNHA UATN'.split(); permutations(words);
It did not take me long to find out that one of those 120 permutations is “HURRICANEORTHEMENACE”.
