python coding contest

Michael Spencer mahs at telcopartners.com
Fri Dec 30 12:02:15 EST 2005


Tim Hochberg wrote:
> Shane Hathaway wrote:
>> Andrew Durdin wrote:
>>
>>> On 12/28/05, Shane Hathaway <shane at hathawaymix.org> wrote:
>>>
>>>
>>>> I just found a 125 character solution.  It's actually faster and more
>>>> readable than the 133 character solution (though it's still obscure.)
>>>
>>> Having spent a good deal of time and effort, and not getting below 144
>>> characters, I am now very eager to see how these shorter versions
>>> work, particularly the 6  120-character solutions. I also expect that
>>> someone (I'll certainly give it a try) will produce a yet shorter
>>> version after the contest closes, based on the knowledge from the
>>> winning solutions.
>>
>> Roberto Alsina fully documented his 120 byte solution here:
>>
>> http://www.pycs.net/lateral/weblog/2005/12/29.html#P333
>>
>> My 120 byte solution is equivalent.  Many others probably did the same 
>> thing.  Python's philosophy of one way to do it seems to be leading us 
>> all down the same road.
>>
>> However, it still feels like there's room for improvement.  I have a 123 
>> byte solution based on a fairly repetitive 21 character string; if I 
>> could compress the representation of the string, it could win.
> 
> Apparently there was as someone put out a 119 byte solution. I can't get 
> to Roberto's code at present (perhaps he's suffering a bandwidth 
> crisis?), but it seems that my 120 character solution is different. It 
> sounds like he encoded his as a row at a time and did two loops one for 
> each character and one for each row. I encoded the data per character 
> and did three loops one per column, one per character and one per row. 
> I'm sure that's not clear, so here's the code:
> 
> 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'm off to try to figure out how to do it the other way now, before the 
> code gets revealed.
> 
> 
> -tim
> -tim
> 
> 
Mine was practically identical, but with another permutation of the loop variables:

seven_seg=lambda n,s="".join:s(
s(" _| |"[ord('w\x12][:koR\x7f{'[int(i)])>>r&j]
for i in n for j in(4,1,2))+"\n"for r in(6,3,0))

More evidence that 'there is one obvious way to do it' ;-)

Still curious about 119, though

Michael






More information about the Python-list mailing list