From: Kero Date: 2005-01-15T19:41:10+09:00 Subject: Re: [SUMMARY] LCD Numbers (#14) > There were three main strategies used for solving the problem. Some used a > template approach, where you have some kind of text representation of your > number at a scale of one. Two might look like this, for example: > > [ " - ", > " |", > " - ", > "| ", > " - " ] [snip] > The second strategy used was to treat each digit as a series of segments that > can be "on" or "off". The numbers easily break down into seven positions: > > 6 > 5 4 > 3 > 2 1 > 0 > > Using that map, we can convert the two above to a binary digit, and some did: > > 0b1011101 [snip] So why not use: LCD = [ "-|| ||-", # 0 " | | ", "- |-| -", "- |- |-", " ||- | ", "-| - |-", # 5 "-| -||-", "-|| | ", "-||-||-", "-||- |-", ] catching the bits and the shapes at the same time. [snip] > The third strategy caught my eye, so I'll examine it here. Let's look > at the primary class of Dale Martenson's solution: > > class LCD > attr_accessor( :size, :spacing ) > > # > # This hash is used to define the segment display for the # given > digit. Each entry in the array is associated with # the following > states: > # > # HORIZONTAL > # VERTICAL > # HORIZONTAL > # VERTICAL > # HORIZONTAL > # DONE My main program looked like hor(0) ver(1, 2) hor(3) ver(4, 5) hor(6) replacing the statemachine. Ah well. This was actually the first Ruby Quiz I made. Partially because it looked like it was really short to work out. Thanks! (perhaps next time I'll even submit it :) +--- Kero ----------------------- kero@chello.nl ---+ | all the meaningless and empty words I spoke | | Promises -- The Cranberries | +--- M38c --- http://httpd.chello.nl/k.vangelder ---+