From: Dr Nancy's Sweetie <kilroy@elvis.rowan.edu>
Subject: Re: Array Of Constant Strings?
Date: Mon, 14 Apr 2003 18:43:26 GMT
Date: 2003-04-14T18:43:26+00:00 [thread overview]
Message-ID: <ijDma.7753$io.287393@iad-read.news.verio.net> (raw)
In-Reply-To: wcclm08159j.fsf@shell01.TheWorld.com
Last February, I wrote about setting arrays of constant strings that
were always the same length and never changed. I got some useful
help on the subject, and a few people expressed concerns such as:
> If all the strings are always the same length, then using fixed
> length strings is even simpler. However, I would tend to be
> suspicious of such a requirement; things like that are almost
> always changed later.
and
> Well, we don't know why the OP wants same-length strings, but
> I agree -- such a restriction seems suspicious.
I wanted to reply at the time, but couldn't, because the question went
to my version of the sample solution of a problem for a programming
contest. Keeping the problem a secret before the contest is obviously
necessary. As we've had the contest (last Saturday), I can explain.
The problem involved parsing out the 95 bits encoded by a UPC-A bar
code, with the bits represented as a string of 1s and 0s. You can read
the whole thing at <http://elvis.rowan.edu/hspc/>, but the short version
is that each digit in the UPC code is represented by 7 bits, and so the
student programs have to split the input string into 7-character chunks
and then check each substring against a table to see which digit it's
supposed to be. Such a limitation is usually a bad idea, but (a) the
UPC-A code is not likely to change much any time soon, given the huge
investment in equipment which currently supports it, and (b) for the
contest problem, I get to define any limits I like. 8-)
The relevant snippets of code are here:
---------------
-- Constants -- values from problem description
---------------
Bit_String_Size : constant Integer := 7;
[...]
subtype Bit_String is String(1..Bit_String_Size);
[...]
-- type for bitstring lookup table
type Encoding_Array is array(0..9) of Bit_String;
-- Lookup tables for extracted bit strings
-- (encodings taken from problem description)
Left_Encoding : constant Encoding_Array :=
("0001101", "0011001", "0010011", "0111101", "0100011",
"0110001", "0101111", "0111011", "0110111", "0001011");
Right_Encoding : constant Encoding_Array :=
("1110010", "1100110", "1101100", "1000010", "1011100",
"1001110", "1010000", "1000100", "1001000", "1110100");
There are other ways to attack this, of course (make a 128-entry
table and interpret the strings as binary numbers to give a direct
lookup, eg), but I wanted a program whose operation would be
understandable to high school students.
Thanks for all your help!
Darren Provine ! kilroy@elvis.rowan.edu ! http://www.rowan.edu/~kilroy
"Fred Rogers was not only the nicest man I ever met, he was the nicest
man ANYONE ever met." -- Robert X. Cringely
next prev parent reply other threads:[~2003-04-14 18:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-14 2:58 Array Of Constant Strings? Dr Nancy's Sweetie
2003-02-14 4:28 ` tmoran
2003-02-14 7:28 ` Dale Stanbrough
2003-02-14 7:47 ` tmoran
2003-02-14 10:06 ` Dale Stanbrough
[not found] ` <19guh-2f4.ln1@beastie.ix.netcom.com>
2003-02-14 19:41 ` Jeffrey Carter
2003-02-14 20:38 ` tmoran
[not found] ` <e0q0i-n14.ln1@beastie.ix.netcom.com>
2003-02-15 22:28 ` Jeffrey Carter
2003-02-22 19:31 ` Robert A Duff
2003-04-14 18:43 ` Dr Nancy's Sweetie [this message]
2003-04-15 11:36 ` Georg Bauhaus
2003-04-15 13:40 ` Dr Nancy's Sweetie
2003-04-15 15:13 ` Georg Bauhaus
2003-04-16 2:17 ` Matthew Heaney
2003-04-16 16:35 ` Chad R. Meiners
2003-04-16 21:03 ` Georg Bauhaus
2003-04-17 17:53 ` Robert A Duff
2003-04-17 20:34 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox