# Python Contest

There is a python contest at http://www.pycontest.net/

The task is writing the shortest program to drive a seven-segment LCD thingy.

I have no hope of winning, but here's a helpful hint:

If your code is any longer than this (191 chars), it will not win ;-)

a=' _ ' b='|_|' c=' ' d=' |' e=' _|' f='|_ ' g='| |' v='agbcddaefaeecbdafeafbaddabbabe' def seven_seg(x): return '\n'.join([eval('+'.join([v[int(l)*3+i]for l in x]))for i in 0,1,2])+'\n'

Note: I edited this item way too many times already ;-)

And yes, I can save two characters moving the return up.

A much uglier, yet much shorter (151) version:

def seven_seg(x):return''.join([''.join(['| ||__ __ || | |'[int('a302ho6nqyp9vxvpeow',36)/10**(int(l)*3+u)%10::7]for l in x])+'\n'for u in 0,1,2])

And yes, that pretty much proves you can write ugly python. And I am giving up. A shorter version probably involves a different algorithm, and I can't find any.

I am particularly proud of saving one character by writing 104004334054154302114514332064 as int('a302ho6nqyp9vxvpeow',36).

Also interesting is that the number I was using there originally started with 4 and was exactly the same length written both ways ;-)

Since that number is pretty arbitrary (it's an index table into the "graphics" array), I just shuffled the 1 and the 4. The 0 would have been better but then it didn't work, of course :-)

Now I'm at 137, but on comp.lang.python newsgroup I've seen a 125 char solution :P

How about sharing the code Remi? ;-)

I managed to reduce your code to 135 bytes... but that gave me nothing better than rank 25. I'm still miles away from the winning 120 bytes.

Sigh...

I just cut and pasted my code from Konqueror to Kate. So, if you get 136 bytes instead of 135, remove the space before "for a in z". It is unnecessary, the same way than before "for u in ()".

Any way, I won't win... So, why not?

------

def seven_seg(z):return''.join(''.join(

' | ||_ ___ ||| |'

[ord('x1eR%$r,.x1264'[int(a)])/u&7::7]

for a in z)+"n"for u in(64,8,1))

------

This is a one-liner. I just cut it in a better way than the automatic formating. Don't add spaces anywhere and don't press RETURN at the end of the line. VoilÃ : 135 bytes of pure ugliness. ;-)

Here is also the 142-byte one-liner I was so proud of because of the 3 nested generators. Not very far by the look but very different though.

------

def seven_seg(z):return''.join(''.join(''.join(

" _| |"[ord("wx12][:koRx7f{"[int(a)])/b&7&n;]

for n in(4,1,2))for a in z)

+"n"for b in(64,8,1))

------

The same advices apply: Don't add spaces, no RETURN.

this is really interesting viewpoint on the subject i might add

Well, the write-up is truly the freshest on this laudable topic.