2017-01-31 8 views
1

私は、一般的な賭けのウェブサイトで使用されているシステムを複製する個人的なプロジェクトに取り組んでいます。私が現在取り組んでいるシステムの一部は、ベットスリップの特定のアキュムレータの累積オッズです。 ダイナミックエクササイズ累積オッズ

2.00 
2.00 
4.00 
10.00 

累積オッズ

が一緒にオッズを乗じて働いている、これはことを意味します

あなたを示すことで私が説明しやすくすることができ、以下の私のbetslipの4つの賭けのオッズは、上記の4つのベットのすべてにベットをして勝利したら、私は1x2x2x4x10xの160xのリターンの10クレジットを1つの価値に賭けます。

上記のベットに「高音」ステークを置く場合、私は今オッズを解決する必要があります。私はこれだけは、私は次の操作を行う必要があることを意味し、リターンを得るために勝つために上記の賭けの3を必要とする:

10クレジットの私の出資比率は現在40枚のクレジットためになるように、4つの別々の賭けである
2 x 2 x 4 = 16 
2 x 2 x 10 = 40 
2 x 4 x 10 = 80 
2 x 4 x 10 = 80 

私は、上記のそれぞれについて10クレジットを持っています。

ベストケースのシナリオは、上記のすべてのベットが勝利し、私のステークス(16 + 40 + 80 + 80)の216xを返すことです。

2 x 2 = 4 
2 x 4 = 8 
2 x 10 = 20 
2 x 4 = 8 
2 x 10 = 20 
4 x 10 = 40 

私は累積オッズは100であることを知っているが、私はこれを書くのに苦労しています:私は「ダブルス」を動作するようにした場合

次の部分は、私が上で立ち往生しています一部であり、 PHPを使って、コードを肥大化させて、私がそれに満足していないところに、私はこれを行う簡単な方法である可能性が高いことを知っていますが、私はそれを理解できないようです。

私のコードで利用できる情報は、オッズと「複数の金額」の配列です。トレブルは3番、ダブルスは2番です。これはダイナミックでなければならないので、20倍のベット(ベットスリップでは20ベット)で2倍、3倍、4倍、倍、5倍などの効果があります。

$multiple = 2; 

/* 
    $multiple is equal to 2, which indicates that I need to return the doubles odds. 
    This number could be any number up to 19 & never higher than count($odds). 
*/ 

$odds = array(
    2.00, 
    2.00, 
    4.00, 
    10.00 
); 

/* 
    This array is will be passed as an argument in my function. 
    It will contain up to 20 different odds. 
*/ 

if($multiple < count($odds)) { 

    /* 
     This is where I need to work out the accumulative odds of doubles, trebles etc dynamically. 

     If correct, code should return: 
     100 for doubles 
     216 for trebles 

     It should also have the ability to return the odds of: 
     four-folds from up to 20 bets 
     five-folds up to 20 bets 
     etc.. 
    */ 

} else { 

    foreach($betOdds as $key => $betOdd) { 
     ($odds == 0.00 ? $odds = $betOdd : $odds *= $betOdd); 
    } 

} 

return $odds; 

はまた、私はおそらく、これは非常によく、そう何でも上の任意の明確化のために気軽に説明していませんでした知っています。

答えて

1

あなたが必要とするものは、数学では「組み合わせ」と呼ばれます。そのような質問has already been askedが提供された答えは、文字列の数字の組み合わせを作る方法を示しています。これは、配列バージョンです:

(注:私は、読みやすくするために、私の例えば26410を使用します)、

class Combinations implements Iterator 
{ 
    protected $c = null; 
    protected $s = null; 
    protected $n = 0; 
    protected $k = 0; 
    protected $pos = 0; 

    function __construct($s, $k) { 
     if(is_array($s)) { 
      $this->s = array_values($s); 
      $this->n = count($this->s); 
     } else { 
      $this->s = (string) $s; 
      $this->n = strlen($this->s); 
     } 
     $this->k = $k; 
     $this->rewind(); 
    } 
    function key() { 
     return $this->pos; 
    } 
    function current() { 
     $r = array(); 
     for($i = 0; $i < $this->k; $i++) 
      $r[] = $this->s[$this->c[$i]]; 
     return is_array($this->s) ? $r : implode('', $r); 
    } 
    function next() { 
     if($this->_next()) 
      $this->pos++; 
     else 
      $this->pos = -1; 
    } 
    function rewind() { 
     $this->c = range(0, $this->k); 
     $this->pos = 0; 
    } 
    function valid() { 
     return $this->pos >= 0; 
    } 

    protected function _next() { 
     $i = $this->k - 1; 
     while ($i >= 0 && $this->c[$i] == $this->n - $this->k + $i) 
      $i--; 
     if($i < 0) 
      return false; 
     $this->c[$i]++; 
     while($i++ < $this->k - 1) 
      $this->c[$i] = $this->c[$i - 1] + 1; 
     return true; 
    } 
} 

今、あなたは、次のループ実行する場合:

foreach(new Combinations(["2", "6", "4", "10"], 3) as $combination) 
{ 
    var_dump($combination); 
} 

あなたが希望しまいます結果:

array(3) { 
    [0]=> 
    string(1) "2" 
    [1]=> 
    string(1) "6" 
    [2]=> 
    string(1) "4" 
} 
array(3) { 
    [0]=> 
    string(1) "2" 
    [1]=> 
    string(1) "6" 
    [2]=> 
    string(2) "10" 
} 
array(3) { 
    [0]=> 
    string(1) "2" 
    [1]=> 
    string(1) "4" 
    [2]=> 
    string(2) "10" 
} 
array(3) { 
    [0]=> 
    string(1) "6" 
    [1]=> 
    string(1) "4" 
    [2]=> 
    string(2) "10" 
} 

また、あなたはすぐに結果配列要素の積を得ることができます:

foreach(new Combinations(["2", "6", "4", "10"], 3) as $combination) 
{ 
    var_dump(array_product($combination)); 
} 

をこれは、次になります:

int(48) // because 2 * 6 * 4 = 48 
int(120) // because 2 * 6 * 10 = 120 
int(80) // because 2 * 4 * 10 = 80 
int(240) // because 6 * 4 * 10 = 240 
+0

パーフェクト!非常にありがとう、私に面倒をたくさん保存しました。 –