Write a python function to calculate number of ways of selecting p non consecutive stations out of n stations


Topic: Write a python function to calculate number of ways of selecting p non consecutive stations out of n stations

Solution

  
def stopping_station( p, n): 
    num = 1
    dem = 1
    s = p 
  
    while p != 1: 
        dem *= p 
        p-=1
      
    t = n - s + 1
    while t != (n-2 * s + 1): 
        num *= t 
        t-=1
    if (n - s + 1) >= s: 
        return int(num/dem) 
    else: 
        return -1
		
		



List all Python Programs