A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python-program-for-number-of-stopping-station-problem/ below:

Python Program for Number of stopping station problem

Python Program for Number of stopping station problem

Last Updated : 23 Jul, 2025

There are 12 intermediate stations between two places A and B. Find the number of ways in which a train can be made to stop at 4 of these intermediate stations so that no two stopping stations are consecutive?

Examples -
Input  : n = 12, s = 4
Output : 126

Input  : n = 16, s = 5
Output : 792
Python3
# Python code to calculate number
# of ways of selecting \'p\' non 
# consecutive stations out of 
# \'n\' stations

def stopping_station( p, n):
    num = 1
    dem = 1
    s = p

    # selecting \'s\' positions
    # out of \'n-s+1\'
    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:
        # if conditions does not
        # satisfy of combinatorics
        return -1

# driver code 
num = stopping_station(4, 12)
if num != -1:
    print(num)
else:
    print("Not Possible")

# This code is contributed by "Abhishek Sharma 44"
Output :
126

Please refer complete article on

Number of stopping station problem

for more details!



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4