From: David Alan Black Date: 2002-01-27T21:07:34+09:00 Subject: Re: Coding challenge :-) Hello -- On Sun, 27 Jan 2002, c p r a s l e y at h o m e dot c o m wrote: > On Sun, 20 Jan 2002 13:50:45 GMT, David Alan Black > wrote in comp.lang.ruby: > > >allowing for out-of-order numbers (which have to be put in > >order), negative numbers, mixed input ("1,8,5,-3,10,-2,3-4", > >which should come out as both "-3--2,1,3-5,8,10" and > >"-3,-2,1,3,4,5,8,10"), etc. > > "-3--2" is ugly. You should use a different range indicator such as > "-3/-2,1,3/5,8,10" or a more Ruby-like "-3..-2,1,3..5,8,10". Ranges of > two units are no more efficiently stated as a range than they would be as > a list of two items, so the ideal result would probably be > "-3,-2,1,3..5,8,10". I wasn't looking for an ideal result; I was looking to create an interesting coding challenge. Actually there's no such thing as an ideal output format here, because people who want to use this type of output in real programs will have different needs. Someone who's looking to generate correct Ruby code will do one thing; someone who's writing a book index will do another. (In fact, the idea for this coding challenge comes from my having written routines in Perl several years ago to help me generate a book index.) The coding challenge wasn't geared toward any specific type of real-world output. That would have to be developed, as needed, on a per-project basis. Since there's no way to universalize what people might actually want the output to look like (the "ideal" of using the Ruby range operator, for example, would have been completely irrelevant to my book index), I decided just to use the unadorned '-' connector across the board. You can think of it as a place-holder for whatever one might actually end up wanting the code of this type to do. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav