I love Norvig's Python posts. He really gets the spirit of the language and has fun with it.
winners, losers = (winners - losers), (losers - winners)21–30 of 75 posts
I love Norvig's Python posts. He really gets the spirit of the language and has fun with it.
winners, losers = (winners - losers), (losers - winners)I am not sure why Norvig omits president Obama. That said, "[mtg]a" does match him, so at least Munroe tries.
Earlier quoted context omitted.
"Write the shortest regex that only matches programs that successfully generate the shortest regex given lists of inclusions and exclusions."
Such a regex cannot exist: 1. Take an existing solution to finding the shortest regex given a list of inclusions an exclusions. 2. Take another unrelated arbitrary program. 3. Combine the two, when the arbitrary program terminates, use the existing solution to solve the problem. 4. Such a regex would have to solve the halting problem to know if the arbitrary program terminates and the existing solution solves the pro…
Although this is probably just pointless nitpicking on my part.
This was posted a few days ago on Code Golf: http://codegolf.stackexchange.com/questions/17718/meta-regex... That link includes a perl 10-liner to do the same.
Can someone explain what does this line mean and why does he use it as heuristic? key=lambda c: 3*len(matches(c, uncovered)) - len(c)
It means to use as the key for max 3 (number of things this pattern matches) - (number of characters in pattern). The basic idea is that patterns that match more things are good, while patterns that are long are bad; if you select the pattern with the maximal score for the above expression it's matching more things than others or is shorter than others, or both. Why the "3 " bit, good question. Would be interesting t…
I think it fails for: findregex(set(['abc']), set(['abcd']))
Can someone explain what does this line mean and why does he use it as heuristic? key=lambda c: 3*len(matches(c, uncovered)) - len(c)
IMHO, sadly, that part is serving as a shibboleth. The clue is how he explains all the simple parts of the script with comments, but leaves this part unexplained, making some of us feel left out of the cool club. Implying: if you don't grasp it immediately you must not be up to it. Overall it's a great post, but as to the cryptic parts of it, it's disappointing to see this kind of thing on the part of someone we all…
Second, seriously?
A line of code that isn't as clear as it could be in an ipython notebook he probably dashed off in an hour is somehow a reflection on his generosity of spirit? I think you need to recheck your expectations.
I love Norvig's Python posts. He really gets the spirit of the language and has fun with it.