Jump to content

UVA LCD Display Thoughts?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
30 replies to this topic

#1
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
MathX and I are working on this problem http://uva.onlinejud...ernal/7/706.pdf but we have no thoughts on it at all.

Basically you are given a size of a number s and a number n and you want to display n in size s.

We both know what it's asking but have no idea on how to even get started.

There are 2s+3 rows so we have a for loop like this:


for (int row=0;row<2*s+3;row++) {


}


Then each digit occupies s+2 columns.

So then we would have another loop in the for loop:


for (int col=0;col<n.length();col++) {


}


where n is the number we are displaying.

Maybe? Any thoughts on how we can go about this would be super. :) Not asking for a solution or any code, just a thought to get started really.

Thanks. :D

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Does it have to be in Java? Can I take on this challenge, just for fun?

I'd tackle it by having a separate object for each number you can display and will contain basic metadata that describes the numbers composition (without giving any actual size info). Then chain them into arrays, with which you'd have some object that takes that array of number objects as an argument, and the size, then parses a large string out of it. You'd put this into a loop, that continues to chain number objects to an array, give that array and the size as an argument to the parser object, and displays those strings until you're done. ^_^
Wow I changed my sig!

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Thanks. We'll try it out.

Let you know how it goes. :)

The judge web site works in Java, C, C++, and Pascal. You could do it in any language you want though. Go for it. :)

#4
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
good one, i think ill try doing that

2d arrays is what im thinking....i dont wanna spoil it
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
I got an idea.

You use a 2D array and you fill the 2D array with the appropriate characters to build each number of size 1.

So [0][0] would be the character for digit 0 in column 0. Then for size 2 you just print [0][0] twice. :)

#6
ThemePark

ThemePark

    Programmer

  • Members
  • PipPipPipPip
  • 124 posts
chili5, that won't work completely, since it would then also print out 2 '|' characters. But if you make a check to see if [0][0] etc contains '|' and in that case print 1 '|' and then spaces, it should work.

For your for loop suggestion, you would then also need another for loop for each column for any number.
for (int ncol=0;ncol<s+2;ncol++) {

}

Other than that, having a basic character array of size 1 actually sounds like a good way to go about it.

#7
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Progress...

Should be able to post code in a couple hours, you guys want to see it or is that a negative?
Wow I changed my sig!

#8
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Sure, I'm not having much luck with this. :(

#9
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
I wrote it in C++, if that matters.
Wow I changed my sig!

#10
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Nah, the language isn't relevant. Did you use a 2d array?

#11
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Nope, I used a string parsing algorithm based on information arrays in the numbers. Here's the numbers.h file, which shows how I represent the numbers in data (you don't need to, but you can convert it to .h since this thing isn't cool with header files. :P):

EDIT: Added the parser.cpp file since it seemed more relevant. You can tell that it's still memory-leak-tastic thanks to the std::auto_ptr<std::vector<Digit*> > never deleting the Digit*s. >_< But I'll get that done soon enough.

Anyway, that's how I did it.
Wow I changed my sig!

#12
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
I looked at that and didn't understand most of it. Nice code though. I almost got my code done. :) I got it so that it displays all the numbers individually. So it should be easy to get it to display a chain of numbers together. :)

It's not the best code but it is working. If this was a contest I would have been eliminated for taking too long. :O I broke each number into five parts and each part of the image has a method. :)