[AlgorithmQuiz/LcdDisplay] [windist], 2004-12-29

   1 digits={
   2     1:["TR","BR"],
   3     2:["T","TR","M","BL","B"],
   4     3:["T","TR","M","BR","B"],
   5     4:["TL","TR","M","BR"],
   6     5:["T","TL","M","BR","B"],
   7     6:["T","TL","M","BL","BR","B"],
   8     7:["T","TL","TR","BR"],
   9     8:["T","TL","TR","M","BL","BR","B"],
  10     9:["T","TL","TR","M","BR","B"],
  11     0:["T","TL","TR","BL","BR","B"],
  12         }
  13 
  14 def render(i,size=1):
  15     number = digits[i]
  16     d = list()
  17     d.append(drawHorBar(number,"T",size))
  18     d.extend(drawVerBar(number,"T",size))
  19     d.append(drawHorBar(number,"M",size))
  20     d.extend(drawVerBar(number,"B",size))
  21     d.append(drawHorBar(number,"B",size))
  22 
  23     return d
  24 
  25 def drawVerBar(number,flag,size):
  26     lines = list()
  27     for i in range(size):
  28         line=""
  29         if flag+"L" in number:
  30             line+='|'
  31         else:
  32             line+=' '
  33         line+=' ' * size
  34         if flag+"R" in number:
  35             line+='|'
  36         else:
  37             line+=' '
  38         lines.append(line)
  39     return lines
  40     
  41 def drawHorBar(number,flag,size):
  42     if flag in number:
  43         return ' ' + '-' * size + ' '
  44     else:
  45         return ' ' * (size + 2)
  46     
  47 
  48 def mergeDigits(digit1, digit2):
  49     for i,r in enumerate(digit1):
  50         r+=' ' + digit2[i]
  51         digit1[i]=r
  52     return digit1
  53 
  54 def display(number,size):
  55     digits = reduce(mergeDigits,[render(int(i),size) for i in str(number)])
  56     print '\n\r'.join(digits)
  57 
  58 if __name__=="__main__":
  59     line = raw_input()
  60     inputs = list()
  61     while line != '0':
  62         inputs.append(map(int,line.split()))
  63         line = raw_input()
  64 
  65     for size, number in inputs:
  66         display(number,size)
web biohackers.net