Bonjour,
Je voudrais atteindre un chiffre donné en X mois de façon progressive.
Voilà ce à quoi j'ai pensé comme algo, avec 500 000 le chiffre donné et 30, le nombre de mois.
Ce qui donne au final:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 $Total = 500000; $totalMonth = 30; echo 'Total : '.number_format($Total, 0, '.', ' ').PHP_EOL; echo 'Total month:'.$totalMonth.PHP_EOL; $i = 0; $totalCreated = 0; $start = intval($totalMonth/2) + intval($totalMonth*0.3); $operator = 'divide'; $lastMonths = intval($totalMonth*0.2); while($i < $totalMonth) { if($operator == 'divide') { $Month = intval(($Total/$totalMonth)/$start); $start--; } else { $Month = intval(($Total/$totalMonth)*$start); $start++; } if($i == ($totalMonth - 1)) { //$Month = $Total - $totalCreated; } $totalCreated += $Month; if($start == 0) { $start = 1; $operator = 'multiply'; } echo 'Month '.$i.' ('.$start.' | '.$operator.'): '.number_format($Month, 0, '.', ' ').PHP_EOL; $i++; } echo 'Total Created:'.number_format($totalCreated, 0, '.', ' ');
Le problème, on atteins pas 500 000. L'écart est encore plus grand si on change le nombre de mois ou le total voulu.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Total : 500 000 Total month:30 Month 0 (23 | divide): 694 Month 1 (22 | divide): 724 Month 2 (21 | divide): 757 Month 3 (20 | divide): 793 Month 4 (19 | divide): 833 Month 5 (18 | divide): 877 Month 6 (17 | divide): 925 Month 7 (16 | divide): 980 Month 8 (15 | divide): 1 041 Month 9 (14 | divide): 1 111 Month 10 (13 | divide): 1 190 Month 11 (12 | divide): 1 282 Month 12 (11 | divide): 1 388 Month 13 (10 | divide): 1 515 Month 14 (9 | divide): 1 666 Month 15 (8 | divide): 1 851 Month 16 (7 | divide): 2 083 Month 17 (6 | divide): 2 380 Month 18 (5 | divide): 2 777 Month 19 (4 | divide): 3 333 Month 20 (3 | divide): 4 166 Month 21 (2 | divide): 5 555 Month 22 (1 | divide): 8 333 Month 23 (1 | multiply): 16 666 Month 24 (2 | multiply): 16 666 Month 25 (3 | multiply): 33 333 Month 26 (4 | multiply): 50 000 Month 27 (5 | multiply): 66 666 Month 28 (6 | multiply): 83 333 Month 29 (7 | multiply): 100 000 Total Created:412 918
Quelqu'un aurait une autre idée ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Total : 500 000 Total month:20 ... Total Created:334 513
Merci.
Partager