Margination and Project Gutenberg

by Brett Fishburne



Listing One

WHILE (CURRENT_LINE_SIZE < MINIMAL_LINE_SIZE)

  Add a Word to the Line



WHILE (ABS(CURRENT_LINE_SIZE - OPTIMAL_LINE_SIZE) > 

                ABS(CURRENT_LINE_SIZE + NEXT_WORD_SIZE - OPTIMAL_LINE_SIZE))

  Add a Word to the Line



IF (CURRENT_LINE_SIZE > MAXIMUM_LINE_SIZE)

  Remove the last word from the line



RETURN (CURRENT_LINE_SIZE)



Listing Two

WHILE (CURRENT_LINE_SIZE < MINIMAL_LINE_SIZE)

  Add a Word to the Line



NEXT_LINE_RESULT = 0

BEST_LINE_RESULT = 0

BEST_CURRENT_LINE = CURRENT_LINE_SIZE



WHILE (CURRENT_LINE_SIZE <= MAXIMUM_LINE_SIZE)

  NEXT_LINE_RESULT = BACK_PROPAGATE(NEXT_WORD)

  IF (ABS((CURRENT_LINE_SIZE - OPTIMAL_LINE_SIZE) + 

                  (NEXT_LINE_RESULT - OPTIMAL_LINE_SIZE)) < 

                  ABS((BEST_CURRENT_LINE - OPTIMAL_LINE_SIZE) + 

                  (BEST_LINE_RESULT - OPTIMAL_LINE_SIZE))

    BEST_LINE_RESULT = NEXT_LINE_RESULT

    BEST_CURRENT_LINE = CURRENT_LINE_SIZE

  Add a Word to the Line



RETURN(BEST_CURRENT_LINE)



Listing Three

WHILE (CURRENT_LINE_SIZE < MINIMAL_LINE_SIZE)

  Add a Word to the Line



NEXT_LINE_RESULT = 0

BEST_LINE_RESULT = 0

BEST_CURRENT_LINE = CURRENT_LINE_SIZE



WHILE (CURRENT_LINE_SIZE <= MAXIMUM_LINE_SIZE)

  IF LINE_VALUES[NEXT_LINE][NEXT_WORD] is not calculated

    INCREMENT LINE_NUMBER

    NEXT_LINE_RESULT = BACK_PROPAGATE(NEXT_WORD)

    LINE_VALUES[LINE_NUMBER][NEXT_WORD] = NEXT_LINE_RESULT

    DECREMENT LINE_NUMBER

  ELSE

    NEXT_LINE_RESULT = LINE_VALUES[NEXT_LINE][NEXT_WORD]

  IF (ABS((CURRENT_LINE_SIZE - OPTIMAL_LINE_SIZE) + 

                       (NEXT_LINE_RESULT - OPTIMAL_LINE_SIZE)) < 

                       ABS((BEST_CURRENT_LINE - OPTIMAL_LINE_SIZE) + 

                       (BEST_LINE_RESULT - OPTIMAL_LINE_SIZE))

    BEST_LINE_RESULT = NEXT_LINE_RESULT

    BEST_CURRENT_LINE = CURRENT_LINE_SIZE

  Add a Word to the Line



RETURN(BEST_CURRENT_LINE)







1



