In this tutorial, we are going to share about a python program for number of stopping station problem with an example. We will also share the algorithm for number of stopping station problem.

1 2 3 4 | Algorithm Input : total numbers of stations n and number of stations train can stop r. Step 1 : For values of n and r calculate the value of p(n,r) = n! / (n-r)! Step 2 : print the value of p(n,r) using std print method. |

Copy the below code and create a new python page and paste to execute to see the program output.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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") |

Below are the input and output of above **python program.**

1 2 3 4 5 | Input : n = 12, s = 4 Output : 126 Input : n = 16, s = 5 Output : 792 |

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

- Python Program to Solve n-Queen Problem with Recursion
- Python Program to Solve the Celebrity Problem
- Python Program to Solve n-Queen Problem without Recursion
- Python Programs on Games
- Python Program to Implement Tower of Hanoi
- Write a program to find the title tags from a given html document
- Bisect Algorithm programs in Python
- Implementation of k-nearest neighbor algorithm in Python
- Python basics for data science
- Pytest | Testing framework for Python programming

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok