It is necessary to break the segment into unequal parts, which will decrease proportionally (you need to graphically display the timeline).

Given:

  1. segment length - can be any number in the range from 100 to 1000;

  2. number of parts - 24;

  3. the length of the first part is ~ 15% + - - the value is not fixed.

In response, I published an owl solution, but I hope to get a more correct, mathematically correct answer.

    2 answers 2

    If the segments form a geometric progression, then for its sum you can write

    L = (0.15 * L) * (q^n-1)/ (q-1) (1 - q^24) / (1 - q) = 6.66666 

    To find the denominator of GP q, you can solve this equation numerically using a binary search or another method

    For the search, we set the search interval (if we know that the segments will decrease - then 0..1) and gradually approach a more or less exact solution (the function is monotonic, therefore any method will converge).

    Here is a very simple method of secants (code did not check)

    enter image description here

     double f(double x) { return (1.0d - exp(24.0d*logf(x)))/(1.0dx) - 6.6666667d; } // a, b - ΠΏΡ€Π΅Π΄Π΅Π»Ρ‹ Ρ…ΠΎΡ€Π΄Ρ‹, epsilon β€” нСобходимая ΠΏΠΎΠ³Ρ€Π΅ΡˆΠ½ΠΎΡΡ‚ΡŒ double findRoot(double a, double b, double epsilon) { while(fabs(b - a) > epsilon) { a = b - (b - a) * f(b) / (f(b) - f(a)); b = a + (a - b) * f(a) / (f(a) - f(b)); } // a, b β€” (i - 1)-ΠΉ ΠΈ i-ΠΉ Ρ‡Π»Π΅Π½Ρ‹ return b; } q = findRoot(0.0d, 1.0d, 0.000001d) 
    • Unfortunately, I do not have enough knowledge to evaluate your answer.) Could you describe the answer in more detail? - Dmytryk
    • And what exactly confuses - a geometric progression or a numerical search for a solution? - MBo
    • numerical search - Dmytryk

     const width = 300; const segments = 24; const startWidth = (width / 100) * 15; const step = 0.9; let result = [startWidth]; let count = 0 //счСтчик ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΠΉ let sum = 99999; // аккумулятор ΠΎΠ±Ρ‰Π΅ΠΉ Π΄Π»ΠΈΠ½Ρ‹ всСх ΠΎΡ‚Ρ€Π΅Π·ΠΊΠΎΠ² //формируСтся массив с Π±Π°Π·ΠΎΠ²Ρ‹ΠΌΠΈ ΠΎΡ‚Ρ€Π΅Π·ΠΊΠ°ΠΌΠΈ for (let i = 0; i < segments - 1; i++) { const item = result[result.length - 1]; result.push(item * step); } //вычисялСтся Ρ€Π°Π·Π½ΠΈΡ†Π° ΠΌΠ΅ΠΆΠ΄Ρƒ Π΄Π»ΠΈΠ½ΠΎΠΉ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠ²ΡˆΠ΅Π³ΠΎΡΡ массива ΠΈ Π½ΡƒΠΆΠ½Ρ‹ΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ΠΎΠΌ //с этой Ρ€Π°Π·Π½ΠΈΡ†Ρ‹ формируСтся массив ΠΎΡ‚Ρ€Π΅Π·ΠΊΠΎΠ² ΠΏΠΎ Ρ‚Π°ΠΊΠΎΠΌΡƒ ΠΆΠ΅ ΠΏΡ€ΠΈΠ½Ρ†ΠΈΠΏΡƒ ΠΊΠ°ΠΊ ΠΈ Π±Π°Π·ΠΎΠ²Ρ‹ΠΉ //ΠΏΠΎΡ‚ΠΎΠΌ эти Π½Π΅Π΄ΠΎΠΎΡ‚Ρ€Π΅Π·ΠΊΠΈ Π²Ρ‹Ρ‡ΠΈΡ‚Π°ΡŽΡ‚ΡΡ ΠΈΠ· Π±Π°Π·ΠΎΠ²Ρ‹Ρ… ΠΎΡ‚Ρ€Π΅Π·ΠΊΠΎΠ² //ΠΈ Ρ‚Π°ΠΊ ΠΏΠΎ ΠΊΡ€ΡƒΠ³Ρƒ, ΠΏΠΎΠΊΠ° сумма всСх ΠΎΡ‚Ρ€Π΅Π·ΠΊΠΎΠ² Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ Ρ€Π°Π²Π½Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎΠΉ Π΄Π»ΠΈΠ½Π΅ while ( count < 500 && Math.floor(sum) > width ) { //Ссли ΠΎΠΊΡ€ΡƒΠ³Π»ΡΡ‚ΡŒ Π² Π±ΠΎΠ»ΡŒΡˆΡƒΡŽ сторону, Ρ‚ΠΎ ΠΊΠΎΠ»-Π²ΠΎ итСрация ΠΌΠ½ΠΎΠ³ΠΎΠΊΡ€Π°Ρ‚Π½ΠΎ увСличиваСтся count++; console.log(`Π˜Ρ‚Π΅Ρ€Π°Ρ†ΠΈΡ β„–: ${count}`) const d = result.reduce((sum, index) => sum + index) - width; const between = [d / segments]; for (let i = 0; i < segments - 1; i++) { const item = between[between.length - 1]; between.push(item * step); } result = result.map((item, index) => { return item - between[index]; }); sum = result.reduce((sum, index) => sum + index); } console.log(result); console.log(`Π‘ΡƒΠΌΠΌΠ° всСх ΠΎΡ‚Ρ€Π΅Π·ΠΊΠΎΠ²: ${result.reduce((sum, index) => sum + index)}`);