# 生成最少的彩票以拥有至少N个好数字

11

“生成”具有1、2、3、4个良好数字的所有票证也很容易。

## 挑战

``````// Input: 3 prameters
min_lottery_tickets(total_numbers_to_choose_from, how_many_numbers_to_choose, how_many_good_numbers_i_want)
``````

``````min_lottery_tickets(50, 5, 3)
``````

`````` min_lottery_tickets(10, 5, 2)
``````

``````1   2   3   4   5
5   6   7   8   9
10  1   2   6   7
10  3   4   8   9
3   4   6   7   8
1   2   3   8   9
1   4   9   5   10
``````

## 谁赢

``````min_lottery_tickets(50, 5, 3)
``````

4

3
@xem这几乎属于Math SE了。他们可能会向您证明这些数字对您不利（尽管确实存在一些中奖号码，值得购买门票）
Cruncher

2

DavidC

2

1

``````function min_lottery_tickets(total_numbers_to_choose_from, how_many_numbers_to_choose, how_many_good_numbers_i_want) {
c(function(result) {
var other = result[result.length - 1];
while (result.length < how_many_numbers_to_choose) {
other++;
for (var i = 0; i < result.length; i++) {
if (other === result[i]) {
break;
}
}
result.push(other);
}
}
if (other <= total_numbers_to_choose_from) {
// Print results
console.log(result);
}
}, total_numbers_to_choose_from, how_many_good_numbers_i_want);
}

function c(next, total_numbers, length, start, results) {
if (!start) start = 1;
if (!results) results = [];

for (var i = start; i <= total_numbers + 1 - length; i++) {
var resultsNew = results.slice(0);
resultsNew.push(i);
if (length > 1) {
c(next, total_numbers, length - 1, i + 1, resultsNew);
} else {
next(resultsNew);
}
}
}
``````

``````> min_lottery_tickets(5, 3, 2)
[ 1, 2, 3 ]
[ 1, 3, 4 ]
[ 1, 4, 5 ]
[ 2, 3, 4 ]
[ 2, 4, 5 ]
[ 3, 4, 5 ]
``````

``````> min_lottery_tickets(10, 5, 2)
[ 1, 2, 3, 4, 5 ]
[ 1, 3, 4, 5, 6 ]
[ 1, 4, 5, 6, 7 ]
[ 1, 5, 6, 7, 8 ]
[ 1, 6, 7, 8, 9 ]
[ 1, 7, 8, 9, 10 ]
[ 2, 3, 4, 5, 6 ]
[ 2, 4, 5, 6, 7 ]
[ 2, 5, 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