Skip to content

Instantly share code, notes, and snippets.

@Nydhal
Last active June 10, 2018 22:48
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 Nydhal/a082b1b308f17cfa0cb9175081cfef2e to your computer and use it in GitHub Desktop.
Save Nydhal/a082b1b308f17cfa0cb9175081cfef2e to your computer and use it in GitHub Desktop.
from sympy import binomial as b
def getA2B(X,Y,x,y):
U,D,s = X==x,Y==y,x+y
u = sum([b(s,i) for i in range(0,y)])
d = sum([b(s,i) for i in range(y+1,s+1)])
r = u*U+b(s,y)+D*d
return r/2**s
print('B(3,4) C(3,3) => ',getA2B(3,4,3,3))
# Problem represnetation :
# Enter destination coordinates B(X,Y) and intercept point C(x,y)
# By definition input should obey X >=x and Y>=y
# Example:
# B
#(0,4) -- (1,4) -- (2,4) -- (3,4)
# | | | |
#(0,3) -- (1,3) -- (2,3) -- (3,3) → C
# | | | |
#(0,2) -- (1,2) -- (2,2) -- (3,2)
# | | | |
#(0,1) -- (1,1) -- (2,1) -- (3,1)
# | | | |
#(0,0) -- (1,0) -- (2,0) -- (3,0)
# A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment