#
# This program computes the total number of lottery combinations for:
# - choosing 6 numbers out of 37
# - choosing 1 power number out of 7
#
# Total combinations = C(37,6) * C(7,1)
#
# We implement an idiomatic binomial coefficient function using the
# multiplicative formula:
#
# C(n, k) = product(i = 1..k) of (n - k + i) / i
#
# Why this method?
# - Avoids huge factorials (37! is extremely large)
# - Keeps intermediate values small and exact
# - Efficient, clean, and idiomatic Ruby
#
def binomial_coefficient(n, k)
return 0 if k > n
# Use symmetry: C(n, k) == C(n, n-k)
k = n - k if k > n - k
result = 1
(1..k).each do |i|
result = result * (n - k + i) / i
end
result
end
# Main program
main_n = 37
main_k = 6
power_n = 7
power_k = 1
main_combos = binomial_coefficient(main_n, main_k)
power_combos = binomial_coefficient(power_n, power_k)
total = main_combos * power_combos
puts "Main combinations (C(37,6)): #{main_combos}"
puts "Power combinations (C(7,1)): #{power_combos}"
puts "Total lottery combinations: #{total}"
=begin
run:
Main combinations (C(37,6)): 2324784
Power combinations (C(7,1)): 7
Total lottery combinations: 16273488
=end