Skip to content

Instantly share code, notes, and snippets.

@beyondlimits
Created August 8, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyondlimits/bb221192ac05adba0ce6ac8ffdbd9346 to your computer and use it in GitHub Desktop.
Save beyondlimits/bb221192ac05adba0ce6ac8ffdbd9346 to your computer and use it in GitHub Desktop.
The binomial coefficients can be arranged in rows to form Pascal’s Triangle (where row n is (n 0),(n 1),...(n n). In which row of Pascal’s Triangle do three consecutive entries occur that are in the ratio 3:4:5?
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from __future__ import print_function
def binomial(n, k):
if n < 0 or k < 0 or k > n:
return 0
if n == k:
return 1
result = n
for i in range(1, k):
result *= n - i
result //= i + 1
return result
def solve_the_problem(maxn = 100):
for n in range(maxn + 1):
for k in range(1, n >> 1):
a, b, c = binomial(n, k - 1), binomial(n, k), binomial(n, k + 1)
if 4*a == 3*b and 5*b == 4*c:
return n, k
n, k = solve_the_problem()
print(n, k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment