python coding contest

Shane Hathaway shane at
Fri Dec 30 18:07:50 CET 2005

Tim Hochberg wrote:
> g=''.join;seven_seg=lambda i:g(
> g(' _|x|'[ord("~$]m'k{d\x7fo"[int(n)])>>s&j]
> for n in i for j in(2,1,4))+'\n'for s in(6,0,3))
> I've replaced the unprintable characters and added some preemptive 
> linebreaks so that hopefully this won't get too munged. It's all clear 
> now, right? Two hints: 6,0,3->row, 2,1,4->column and the 6 and 1 have to 
> be where they are to exploit the property that the top row only ever has 
> a center character in it. That way things can be encoded in 7-bits and 
> fit in a character string that Python likes. The order of the other loop 
> indices is mostly accidental but not all permutations may work.

I worked on a similar solution, but didn't have the idea of iterating 
over a series of masks as you did with the 'j' variable.  Good work.

> I'm off to try to figure out how to do it the other way now, before the 
> code gets revealed.

We should have more contests like this.  While the skills I applied for 
the contest don't have much practical value, the mental exercise was great.


More information about the Python-list mailing list