美文网首页
iOS 双色球 大乐透 计算注数与金额 胆拖

iOS 双色球 大乐透 计算注数与金额 胆拖

作者: Faith_K | 来源:发表于2019-12-20 14:42 被阅读0次

    1.计算双色球注数需要用到排列组合算法固定公式

    - (NSInteger)combinationSelectedNum:(NSInteger)n rulesNum:(NSInteger)m{
        if (n < 1 || m < 0 || n < m) {
            return 0;
        }
        // 第一种
        if (m == 0 || m == n) {
            return 1;
        }
        // 第二种
        if (m == 1 || m == n - 1) {
            return n;
        }
        // 第四种 -> 为了减少while循环
        if (m > n / 2) {
            return [self combinationSelectedNum:n rulesNum:n-m];
        }
        // 第三种
        int numerator = 1;
        int denominator = 1;
        while (m > 0) {
            numerator *= n;
            n--;
            
            denominator *= m;
            m--;
        }
        return numerator / denominator;
    }
    
    

    2.计算双色球普通选择的注数

    //计算普通双色球默认选中的数量 与金额
    - (void)calculateTheDoubleChromosphereDefault:(BallType)ballType{
        BallSectionModel *redBall = self.ballListArray.firstObject;
        BallSectionModel *buleBall = self.ballListArray.lastObject;
        NSInteger redRulesNum =0;
        NSInteger buleRulesNum =0;
        if (ballType == DoubleChromosphereBall) {
         //双色球
            redRulesNum = 6;
            buleRulesNum = 1;
        }else if (ballType ==DringsType){
            //大乐透
            redRulesNum = 5;
            buleRulesNum = 2;
        }
        NSInteger redNum =  [redBall combinationSelectedNum:redBall.ballSelectedNum rulesNum:redRulesNum];
        NSInteger buleNum =  [buleBall combinationSelectedNum:buleBall.ballSelectedNum rulesNum:buleRulesNum];
        //得到注数
        self.noteNumber = [NSString stringWithFormat:@"%ld",redNum * buleNum];
        self.price = [NSString stringWithFormat:@"%.2f",self.noteNumber.doubleValue *2.0f];
    }
    
    

    2.计算双色球胆拖选择的注数

    //计算普通双色球胆拖 注数与金额
    - (void)calculateTheDoubleChromospherebileDrag:(BallType)ballType{
        //M 拖码
        NSInteger redNum = 0;
        NSInteger buleNum = 0;;
        //计算双色球
        if (ballType == DoubleChromosphereBall) {
            //胆码
            BallSectionModel *braveryBall = self.ballListArray.firstObject;
            //拖码
            BallSectionModel *dragBall = self.ballListArray[1];
            //篮球
            BallSectionModel *buleBall = self.ballListArray.lastObject;
            redNum =  [braveryBall combinationSelectedNum:dragBall.ballSelectedNum rulesNum:6-braveryBall.ballSelectedNum];
            buleNum =  [buleBall combinationSelectedNum:buleBall.ballSelectedNum rulesNum:1];
        }
        //大乐透
        if(ballType == DringsType)
        {
            /**
             选了6个红拖码  2个红胆码
             选了3个蓝拖码  1个蓝胆码
             int total = C(6, 5 - 2) * C(3, 2 - 1)
             */
            //胆码
            BallSectionModel *sectionModel1 = self.ballListArray[0];
            BallSectionModel *sectionModel2 = self.ballListArray[1];
            BallSectionModel *sectionModel3 = self.ballListArray[2];
            BallSectionModel *sectionModel4 = self.ballListArray[3];
            redNum =  [self combinationSelectedNum:sectionModel3.ballSelectedNum rulesNum:5-sectionModel1.ballSelectedNum];
    
            buleNum =  [self combinationSelectedNum:sectionModel4.ballSelectedNum rulesNum:2 -sectionModel2.ballSelectedNum];
        }
    //    注数
        self.noteNumber = [NSString stringWithFormat:@"%d",redNum * buleNum];
        self.price = [NSString stringWithFormat:@"%.2f",self.noteNumber.doubleValue *2.0f];
    }
    

    相关文章

      网友评论

          本文标题:iOS 双色球 大乐透 计算注数与金额 胆拖

          本文链接:https://www.haomeiwen.com/subject/onqinctx.html