Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@yopya

# Project Euler 53「組み合わせ選択」

More than 3 years have passed since last update.

ワンライナーって気持ちいい。
でも 次の問題 をチラ見したらクソ程めんどくさそうで若干萎え気味。

# Problem 53 「組み合わせ選択」

12345から3つ選ぶ選び方は10通りである.
123, 124, 125, 134, 135, 145, 234, 235, 245, 345.

ここで, n! = n×(n−1)×...×3×2×1, 0! = 1 と階乗を定義する.
n = 23 になるまで, これらの値が100万を超えることはない: \$_{23}C_{10} = 1144066\$
1 ≤ n ≤ 100 について, 100万を超える \$_nC_r\$ は何通りあるか?

``````def hoge(max_n, limit):
f = lambda n: n * f(n-1) if n > 0 else 1
C = lambda n, r: f(n) // (f(r) * (f(n-r)))
return sum( 1 for n in range(1, max_n+1) for r in range(1, n+1) if C(n, r) > limit )

print(hoge(100, 1000000))
``````
1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away