the approach

Add a reply

Posted by graydot 675 days ago:
so how did everyone approach this?

My way is by looking at what part of the line we are writing (1-8) and write the line according to the block set for that digit.
Posted by Mr Zing 654 days ago:
I just did each row individually for each number in the sequence of numbers given to us. It works fine, and I can cut the program down by about 200 bytes without losing too much readability (removing all the whitespace), though I can't see how I can cut my program down much more after that, without changing the way I did it, or alternatively, significantly reducing the readability, which is something I don't want to do.

I did define a new class though - if I had just created a method of the Object class, that would also reduce my program size considerably. (PS: I use/used Ruby)

I'm happy with what I've done though; being a beginner programmer and all, I'm just looking to produce a 'nice' solution that works. I'm not looking to be at the top spot or anything like that, although it would be nice. :-/
Posted by mick 617 days ago:
Spoiler alert!

Ok, maybe this isn't a total spoiler, since I'm not providing any working code or a complete algorithm, but here's how I approached it (including a line of thinking that I rejected):

I started by looking at how I would break up the problem row by row, and I noticed that there were only 5 distinct patterns of rows:
r1=" " # nothing on
r2=" ### " # horizontal segment is on
r3="# " # left side is on
r4=" #" # right side is on
r5="# #" # both left and right are on

The first, fifth, and ninth rows could only be r1 or r2. The other rows could be one of: r1, r3, r4, or r5. I was imagining that assembling the final display from these rows would look like this:

rows=[[r2,r5,r5,r5,r1,r5,r5,r5,r2], # defining zero row-by-row
[r1,r4,r4,r4,r1,r4,r4,r4,r1], # defining one row-by-row
...etc...


However, it seemed quite costly to define these five constants and my 'rows' array. So next, I tried to think about how the seven segments were organized, and I realized that they formed a regular pattern:


_#_ abc _0_
#_# def 1_2
_#_ ghi _3_
#_# jkl 4_5
_#_ mno _6_

The seven segments are located at evenly spaced points on this 3x5 grid: abcdefghijklmno= _0_1_2_3_4_5_6_. So each number could be fully represented in 7 bits if you take the step of mapping 0=>b, 1=>d, 2=>f, etc. Or you could represent each number in 15 bits, if you wanted to fully specify all fifteen bits [a-o].

Then, looking at the bigger numbers, I realized that they were just:

abbbc
deeef
deeef
deeef
ghhhi
jkkkl
jkkkl
jkkkl
mnnno


Since I was working in Python, it seemed natural to build these larger numbers by cascading some slicing/mapping operations and reassembling the pieces.

Were there other dramatically different approaches?
Posted by pbx 617 days ago:
I took a very similiar approach, and with a few other sneaky tricks (related to how I encoded the line-representations and the digit-to-representation mappings) got it down to 160B.

What is this "readability" thing that Mr Zing is going on about?

Add a reply