My script has been changed to accommodate python3 (iteritems is gone and replaced by items — not sure whether it is a fair replacement). For method names and how they are implemented, please refer to script or the blog post.
Following chart shows the comparison. PyPy does not boost up the performance for simple reason that dictionary sorted is not large enough. I’ve put it here just for making a point and PyPy can slow thing down on small size computation.
The linux utility grep is great. But somehow I do not like it. Too much to remember and regex format sucks.
I wrote a python script which does something similar. This is how one should use this script
./sniff.py path pattern_to_search [file_pattern]
First argument path is the directory in which we want to search. It will search recursively inside dir. Second argument pattern_to_search is a regular expression which we want to search in a file. This regex in defined in python re library. The . matches newline alos.
Third argument file_pattern is optional. This is regular expression of filename. Only those files which matches this regex will be considered. For example if I want to search python files with extension py containing Pool( followed by Adaptor, I do the following,
Recently, a friend taught me a simple game of bulls and cows. This game goes like this. There are two players, A and B. A thinks of a 4-letter word and asks B to guess it. Assume that A thought of “link” and B guesses “lean”. The bulls are the number of letters which are common to both words at the same location in both words , for example “l” is a bull in “link” and “lean”. The cows are number of letters which are common to both words but not bull. Letter “l” and “n” are common to both but “l” is the bull, so “n” is the only cow. This guess or “lean” has one bull and one cow. Player A tells B the number of bulls and cows. This helps B in making the next guess; the process goes on till B finds the word.
I wrote a python program to play this game on your computer. I am not sure if it will work on windows. It will definitely work on Linux. Check out repository implementation of the game.
I will also write an algorithm which would find the word of A in minimum steps.