# [Tutor] Re: "Big Letters".

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Jan 15 15:22:24 EST 2004

On Thu, 15 Jan 2004, Abel Daniel wrote:

> Jorge Godoy writes:
> > Does anyone know of a Python module that can generate big letters as
> > those seen on POS for text mode? It seems that curses can't generate
> > them by itself...
>
> Although not a python module, figlet (http://www.figlet.org/) is a nice
> program which generates texts like these. You could open a pipe to it
> and write to it's stdin and read from it's stdout.

On a tangent note, has anyone seen:

http://online-judge.uva.es/portal/modules/acmproblemset/

yet?  I'm starting to read through the book "Programming Challenges: The
Programming Contest Training Manual", and it looks like a great source of
practice problems!

Jorge's question touches on one of the contest challenges, an LCD number
displayer problem:

http://online-judge.uva.es/problemset/v7/706.html

*grin* Anyone want to try their hand at this?

Talk to you later!

*** spoiler space below ***

*** spoilers ahead ***

Here's my crack at the LCD problem:

###
"""An LCD displayer.

Danny Yoo (dyoo at hkn.eecs.berkeley.edu)

A solution for:

http://online-judge.uva.es/problemset/v7/706.html
"""

from sys import stdout

def main():
while 1:
line = raw_input()
if not line: break
size, digits = line.split()
if (size, digits) == ('0', '0'):
break
draw_digits(digits, int(size))

"""
An LCD digit is composed of 7 components:

0
1 2
3
4 5
6

So we keep a map between digits and the LCD pattern to generate that
digit.
"""
LCD_DATA = { '0': (1, 1, 1, 0, 1, 1, 1),  ## zero
'1': (0, 0, 1, 0, 0, 1, 0),  ## one
'2': (1, 0, 1, 1, 1, 0, 1),  ## two
'3': (1, 0, 1, 1, 0, 1, 1),  ## three
'4': (0, 1, 1, 1, 0, 1, 0),  ## four
'5': (1, 1, 0, 1, 0, 1, 1),  ## five
'6': (1, 1, 0, 1, 1, 1, 1),  ## six
'7': (1, 0, 1, 0, 0, 1, 0),  ## seven
'8': (1, 1, 1, 1, 1, 1, 1),  ## eight
'9': (1, 1, 1, 1, 0, 1, 1),  ## nine
}

def draw_digits(digits, size):
draw_horizontals(digits, size, 0)
for i in range(size):
draw_verticals(digits, size, 1, 2)
draw_horizontals(digits, size, 3)
for i in range(size):
draw_verticals(digits, size, 4, 5)
draw_horizontals(digits, size, 6)

def draw_horizontals(digits, size, component):
for d in digits:
space()
if LCD_DATA[d][component] == 1:
dash(size)
else:
space(size)
space()

space() ## one space between each digit
newline()

def draw_verticals(digits, size, component1, component2):
for d in digits:
if LCD_DATA[d][component1] == 1:
bar()
else:
space()
space(size)
if LCD_DATA[d][component2] == 1:
bar()
else:
space()

space() ## one space between each digit
newline()

def dash(size):
"""Write out a dash."""
stdout.write("-" * size)

def bar():
"""Write out a bar."""
stdout.write("|")

def space(size = 1):
"""Write out a space."""
stdout.write(" " * size)

def newline():
"""Write out a newline."""
stdout.write("\n")

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