moon_aka_sun: (Default)
moon_aka_sun ([personal profile] moon_aka_sun) wrote2006-01-28 09:05 pm
Entry tags:

Семисегментный индикатор

http://www.pycontest.net/job/: Subject of the contest is to code the shortest possible python module that converts decimal numbers to the seven-segment display format.

>>> import seven_seg
>>> print seven_seg.seven_seg('0123456789')
 _     _  _     _  _  _  _  _ 
| |  | _| _||_||_ |_   ||_||_|
|_|  ||_  _|  | _||_|  ||_| _|

Постепенно пришёл от первоначальной версии в 209 символов...

def seven_seg(x):
  m=' _ $   $|_|$| |$  |$ _|$|_ '.split('$')
  p=q=r=''
  for d in x:
    s=ord("'a98S?<0 #"[int(d)])-16
    p+=m[s//49]
    q+=m[s//7%7]
    r+=m[s%7]
  return p+"\n"+q+"\n"+r+"\n"
...к 127 символьному однострочнику:

seven_seg=lambda x,j=''.join:j(j(" _    |_| |_ _|"[(ord("HjXYqRO9AD"[int(d)])-41)/i%7*2:][:3]for d in x)+'\n'for i in (49,7,1))


Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting