Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.97 KB | None | 0 0
  1. <?php
  2.  
  3. // Форматирование вывода
  4. function addSpace($data, $spaceLength, $append = false) {
  5.     $dataLength = strlen((string)$data);
  6.     if ($dataLength < $spaceLength) {
  7.         for ($i=0; $i < $spaceLength-$dataLength; $i++) {
  8.             if($append)
  9.                 $data .= ' ';
  10.             else
  11.                 $data = ' '.$data;
  12.         }
  13.     }
  14.  
  15.     return ($data);
  16. }
  17.  
  18. // Вычисляем первую ставку
  19. function calcBet($deposit, $profitFactor, $lossIndex) {
  20.  
  21.     $factorSum = 1;
  22.     for ($i = 1; $i < $lossIndex; $i++) {
  23.         $factorSum += pow( (1 + (100 / (($profitFactor * 100) - 100))) , $i);
  24.     }
  25.  
  26.     return round($deposit/$factorSum);
  27. }
  28.  
  29. $deposit = 5000;
  30. $profitFactor = 1.6;
  31. $lossIndex = 5;
  32. $calcBet = calcBet($deposit, $profitFactor, $lossIndex);
  33.  
  34. $summaryCredit = 0;
  35. $betList = array();
  36. for($round = 1; $round <= $lossIndex; $round++) {
  37.     $bet = $calcBet + round(($summaryCredit * 100) / (($profitFactor * 100) - 100));
  38.     $summaryCredit += $bet;
  39.  
  40.     $profit = round($bet * $profitFactor);
  41.     $betList[] = array(
  42.         'bet' => $bet,
  43.         'credit' => $bet - ($bet*2),
  44.         'summaryCredit' => $summaryCredit - ($summaryCredit*2),
  45.         'profit' => $profit,
  46.         'summaryProfit' => $profit - $summaryCredit,
  47.     );
  48. }
  49.  
  50. echo 'Deposit: '.$deposit.PHP_EOL;
  51. echo 'Profit Factor: '.$profitFactor.' (+'.(($profitFactor * 100) - 100).'%)'.PHP_EOL;
  52. echo 'Loss Index: '.$lossIndex.PHP_EOL.PHP_EOL;
  53. echo 'N  |Bet     |Credit  |SumCredit |Profit  |SumProfit |Deposit (Loss)';
  54. echo PHP_EOL;
  55. $i=0;
  56. foreach ($betList as $bet) {
  57.     $i++;
  58.     echo addSpace($i, 3).'|';
  59.     echo addSpace($bet['bet'], 8).'|';
  60.     echo addSpace($bet['credit'], 8).'|';
  61.     echo addSpace($bet['summaryCredit'], 10).'|';
  62.     echo addSpace($bet['profit'], 8).'|';
  63.     echo addSpace($bet['summaryProfit'], 10).'|';
  64.     echo addSpace($deposit - ($bet['summaryCredit'] - ($bet['summaryCredit']*2)), 14).'|';
  65.     echo PHP_EOL;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement