logic puzzle / 4gl report challenge
Posted in 1996
OK, *I* thought this was an interesting little problem to share with the world (your kilometerage may vary). Suppose I want a report that will list all the integers that appear in a certain column of a certain table. The following program: {----------} database mydatabase main define p_num integer declare c1 cursor for select unique int_col from some_table order by 1 start report rpt1 to "rpt1.out" foreach c1 into p_num output to report rpt1 ( p_num ) end foreach finish report rpt1 end main {----------} report rpt1 ( current_number ) define current_number integer define this_is_the_first_item smallint format first page header let this_is_the_first_item = TRUE on every row if ( not this_is_the_first_item ) then print ", " ; end if print current_number using "<<<<<<" ; let this_is_the_first_item = FALSE on last row print "" end report {----------} will generate the following report: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 81, 85, 101, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333 (I added line breaks to enhance readability on terminals that truncate text instead of wrap it - in the actual report the numbers appear all on one line, separated by commas.) Now let us imagine that my user says: That's much too hard to read! Please print the numbers out like this... 1-17, 19-27, 30-36, 38-55, 81, 85, 101, 323-333 Question... problem... challenge... How would you modify report "rpt1" to produce the required output? This had me obsessed for a day or so (I know, I should get a life) - I have a solution but there is probably a better one waiting to be discovered. I'll post it later if anyone expresses any interest. - Paul ************************************************************************* Disclaimer: All opinions expressed in this message are well-reasoned and insightful; needless to say, they are not those of Informix Software, its partners or lackeys. Anyone who says otherwise is itching for a fight.