in reply to Re^2: chapters,sentences, and arrays
in thread chapters,sentences, and arrays
It would also be fairly trivial if each chapter had the same number of sentences. One trick might be then to find the chapter with the most number of sentences and pad each chapter to be equal to that chapter. When you "hand out" sentences and their ordinal value, there will be gaps representing the padding but you can then instantly take any sentence and find which chapter it belongs to. You can also find its true overall ordinal value in the book as well as the ordinal value in the chapter. Consider the following:
Chapter 1: 3 sentences Chapter 2: 5 sentences Chapter 3: 4 sentences Chapter 4: 6 sentences The chapter with the longest chapter is 4, so we pad all of them to 6 Chapter 1: 01, 02, 03 # 04, 05, 06 are padded real: 01, 02, 03 Chapter 2: 07, 08, 09, 10, 11 # 12 is padded real: 04, 05, 06, 07, 08 Chapter 3: 13, 14, 15, 16 # 17 and 18 are padded real: 09, 10, 11, 12 Chapter 4: 19, 20, 21, 22, 23, 24 # no padding real: 13, 14, 15, 16, 17, 18 Now let's say someone says, what chapter does 15 belong to? ceil(15 / 6) = 3 Now let's say someone wants to know the true ordinal overall value my %pad = (1 => 0, 2 => 3, 3 => 4, 4 => 6); 15 - $pad{ceil(15 / 6)} = 11 Now let's say someone wants to know what is the ordinal value of the s +entence within the chapter 15 mod 6 = 3
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: chapters,sentences, and arrays
by ikegami (Patriarch) on Oct 22, 2008 at 18:22 UTC | |
|
Re^4: chapters,sentences, and arrays
by Perlbotics (Archbishop) on Oct 23, 2008 at 19:40 UTC |