# My Web: MindEchoes.com

## Saturday, April 24, 2010

### Programming Challenges: The Programming Contest Training Manual (4)

Cualquier bug encontrado o mejora que se pueda hacer al código, se agradecen los comentarios!

Problema 1.6.4: LCD Display
A friend of yours has just bought a new computer. Before this, the most powerful
machine he ever used was a pocket calculator. He is a little disappointed because he
liked the LCD display of his calculator more than the screen on his new computer! To
make him happy, write a program that prints numbers in LCD display style.

Input
The input file contains several lines, one for each number to be displayed. Each line
contains integers s and n, where n is the number to be displayed (0 ≤ n ≤ 99, 999, 999)
and s is the size in which it shall be displayed (1 ≤ s ≤ 10). The input will be terminated
by a line containing two zeros, which should not be processed.

Output
Print the numbers specified in the input file in an LCD display-style using s “-” signs
for the horizontal segments and s “|” signs for the vertical ones. Each digit occupies
exactly s + 2 columns and 2s + 3 rows. Be sure to fill all the white space occupied by
the digits with blanks, including the last digit. There must be exactly one column of
blanks between two digits.
Output a blank line after each number. You will find an example of each digit in the
sample output below.

Sample Input
2 12345
3 67890
0 0

Sample Output
Solución;
```n1 = ['   ', ' | ', '   ', ' | ', '   ']
n2 = [' - ', ' .|', ' - ', '|. ', ' - ']
n3 = [' - ', ' .|', ' - ', ' .|', ' - ']
n4 = [' . ', '|.|', ' - ', ' .|', ' . ']
n5 = [' - ', '|. ', ' - ', ' .|', ' - ']
n6 = [' - ', '|. ', ' - ', '|.|', ' - ']
n7 = [' - ', ' .|', ' . ', ' .|', ' . ']
n8 = [' - ', '|.|', ' - ', '|.|', ' - ']
n9 = [' - ', '|.|', ' - ', ' .|', ' - ']
n0 = [' - ', '|.|', ' . ', '|.|', ' - ']

dictN = {'1':n1, '2':n2, '3':n3, '4':n4, '5':n5,
'6':n6, '7':n7, '8':n8, '9':n9, '0':n0}

def main():
f = open('input164', 'r')
for line in input:
nums = line.replace('\n', '').split(' ')
create_numbers(int(nums), nums)

def create_numbers(s, num):
if s > 0:
numbers = ''
for i in range(5):
line = ' '.join([dictN[n][i] for n in num]) + '\n'
line = line.replace('.', ' '*s)
line = line.replace('-', '-'*s)
if i == 1 or i == 3:
line = line * s
numbers += line
print numbers

if __name__ == '__main__':
main()
```