Sign in to follow this  
Followers 0
Kotrin

LCD Numbers

2 posts in this topic

This is one of my more favorite challenges from RubyQuiz just because it's quasi useful and fun to do.

[quote]This week's quiz is to write a program that displays LCD style numbers at adjustable sizes.

The digits to be displayed will be passed as an argument to the program. Size should be controlled with the command-line option -s follow up by a positive integer. The default value for -s is 2.[/quote]

[url="http://rubyquiz.com/quiz14.html"]Visist Here For Example + Tips + Answers[/url]

p.s. Good to be back :)

Share this post


Link to post
Share on other sites
This is in python, and I know I can make it alot tighter. I had to copy/paste more then once, and that is always a bad sign. Suggestions are welcome, but I'm not reading them until I try it again. It also showed me that I have no idea how to properly process command line options, I should look into that.

[spoiler][code]
import sys

def lcdtext(numbers2display,size):
hor = "-" * size
nhor = " " * size
output = ""
numbers2display = list(str(numbers2display))
#print any top -'s
for number in numbers2display:
if number in "02356789":
output = output + " " + hor + " "
else:
output = output + " " + nhor + " "
output = output + "\n"
#print the first set of |'s
for vert in range(1, size + 1):
for number in numbers2display:
if number in "045689":
output = output + "|" + nhor
else:
output = output + " " + nhor
if number in "01234789":
output = output + "|"
else:
output = output + " "
output = output + " "
output = output + "\n"
#print any middle -'s
for number in numbers2display:
if number in "2345689":
output = output + " " + hor + " "
else:
output = output + " " + nhor + " "
output = output + "\n"
#print the second set of |'s
for vert in range(1, size + 1):
for number in numbers2display:
if number in "0268":
output = output + "|" + nhor
else:
output = output + " " + nhor
if number in "013456789":
output = output + "|"
else:
output = output + " "
output = output + " "
output = output + "\n"
#print any bottom -'s
for number in numbers2display:
if number in "023568":
output = output + " " + hor + " "
else:
output = output + " " + nhor + " "
output = output + "\n"
print output


def main():
size = 2
# lcdtext(numbers2display,size)
args = sys.argv
sizenext = False
for arg in args:
if arg == '-s':
sizenext = True
elif sizenext:
size = int(arg)
sizenext = False
else:
numbers2display = arg
lcdtext(numbers2display,size)
if __name__ == '__main__':
main()
[/code][/spoiler] Edited by Lord Wud

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0