0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

組み合わせ数の合計を出す(メモ)

Last updated at Posted at 2019-11-20

(32個から1個取り出すときの組み合わせ)+(32個から2個取り出すときの組み合わせ)+(32個から3個取り出すときの組み合わせ)+...というようにやっていって最終的に31個取り出すまでの組み合わせ数の合計を知りたくて作りました

num = 32
r = 1
sum = 0

while r < num do
  n = num
  i = r
  numerator = 1
  denominator = 1
  while i > 0 do
    denominator = denominator * i
    numerator = numerator * n
    n = n - 1
    i = i - 1
  end
  result = numerator / denominator
  puts "[#{num}C#{r}]#{result}"
  sum = sum + result
  r = r + 1
end
puts "合計#{sum}通り"

実行結果↓
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?