Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Math problem
#15
(05-05-2023, 09:53 PM)programmer_ceds Wrote: Not sure that it would make any difference but the line of code:

Code:
window_samples_to_process -= repeat_width - offset;
should be as follows to avoid doubt:

Code:
window_samples_to_process -= (repeat_width - offset);

My code defined the offset as the distance of the left-hand edge of the window after the left-hand edge of the preceding line. So in the following example:

Code:
SSSSSLLSSSSSLLSSSSSLLSSSSSLL 1: 15
     --------------------
the offset would be 1. A complete repeat is defined as a line followed by a space. Because the offset (1) is <= the line width (2) the first section of the code determines that there are 5 spaces in the first partial repeat. Then it subtracts the repeat length (7) minus the offset (1) from the number of samples still to process (20) to give 14. Dividing this by the repeat length gives 2. Multiplying 2 by the width of the spaces (5) gives 10 which added to the 5 from the initial partial repeat gives an answer of 15 spaces. In this case there is no partial repeat at the end so the final two lines have no effect.

In the case of:

Code:
SSSSSLLSSSSSLLSSSSSLLSSSSSLL 2: 14
    --------------------

the offset is 0. Since the offset is zero the first 'partial' repeat is actually a complete repeat but it doesn't matter that it is treated as a partial repeat and, as the offset is <= the line width the first section of code again determines that the initial partial repeat contains 5 spaces. Then it subtracts the repeat length (7) minus the offset (0) from the number of samples still to process (20) to give 13. Dividing by the repeat length (7) gives 1 - so the middle section of the code adds 1 * 5 spaces to the previous 5 to give 10. The number of samples still to process is reduced by the repeat width (7) * the number of repeats (1) to leave 6 samples still to process. The final section of code determines that the number of samples still to process is > the line width and so increases the number of spaces in the window by the number of samples still to process (6) minus the line width (2) = 4. This should give a total of 14 spaces.

I think it may simply be a matter of where the offset is measured from. If you want to define this in another way and you are still stuck I'll rework to code to use your definition of the offset.

Hope this helps.

Well at that point it was just a matter of curiosity. For real-life I wouldn't be defining the function on the fly. My own code, although less mathematically elegant(*), as the side benefit that it is a very simple matter to make also return the number of pieces, which is used in a progress indicator.

(*) but maybe  it can be improved with floor/ceil, I hate if statements...
Reply


Messages In This Thread
Math problem - by Ofnuts - 05-02-2023, 08:45 AM
RE: Math problem - by PixLab - 05-03-2023, 08:47 AM
RE: Math problem - by rich2005 - 05-03-2023, 10:17 AM
RE: Math problem - by Ofnuts - 05-04-2023, 10:51 AM
RE: Math problem - by rich2005 - 05-04-2023, 11:05 AM
RE: Math problem - by Ofnuts - 05-04-2023, 11:45 AM
RE: Math problem - by programmer_ceds - 05-04-2023, 05:33 PM
RE: Math problem - by rich2005 - 05-04-2023, 12:27 PM
RE: Math problem - by Ofnuts - 05-04-2023, 12:58 PM
RE: Math problem - by Ottia Tuota - 05-04-2023, 05:34 PM
RE: Math problem - by Ofnuts - 05-05-2023, 04:50 PM
RE: Math problem - by Ottia Tuota - 05-05-2023, 07:12 PM
RE: Math problem - by Ofnuts - 05-05-2023, 08:04 PM
RE: Math problem - by programmer_ceds - 05-05-2023, 09:53 PM
RE: Math problem - by Ofnuts - 05-05-2023, 10:54 PM
RE: Math problem - by Ottia Tuota - 05-06-2023, 08:23 AM
RE: Math problem - by programmer_ceds - 05-06-2023, 10:22 AM
RE: Math problem - by Ottia Tuota - 05-06-2023, 07:52 PM
RE: Math problem - by Ofnuts - 05-06-2023, 09:05 PM

Forum Jump: