
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to find all contiguously increasing numbers in start end range in Python
Suppose we have two numbers start and end, we have to find a sorted list of integers such that every number e in range [start, end] both inclusive and the digits of e are contiguously increasing. An example of continuously increasing number is 5678, but 169 is not.
So, if the input is like start = 10 end = 150, then the output will be [12, 23, 34, 45, 56, 67, 78, 89, 123]
To solve this, we will follow these steps −
- s := all 9 digits as a string "123456789"
- a := a new list
- for i in range 0 to 8, do
- for j in range i + 1 to 9, do
- x := (substring of s from index i to j-1) as number
- if start <= x <= end, then
- insert x into a
- for j in range i + 1 to 9, do
- sort the list a and return
Example
Let us see the following implementation to get better understanding −
def solve(start, end): s = "123456789" a = [] for i in range(9): for j in range(i + 1, 10): x = int(s[i:j]) if start <= x <= end: a += (x,) return sorted(a) start = 10 end = 150 print(solve(start, end))
Input
10, 150
Output
[12, 23, 34, 45, 56, 67, 78, 89, 123]
- Related Articles
- Program to find length of longest contiguously strictly increasing sublist after removal in Python
- Display all the numbers from a range of start and end value in JavaScript?
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Program to find bitwise AND of range of numbers in given range in Python
- Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers
- Program to sort all even and odd numbers in increasing and decreasing order respectively in Python
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- MySQL query to count days in date range with start and end date
- Program to count total number of set bits of all numbers in range 0 to n in Python
- Program to find out the number of special numbers in a given range in Python
- Program to find start indices of all anagrams of a string S in T in Python
- Program to find all missing numbers from 1 to N in Python
- Python Program to Determine all Pythagorean Triplets in the Range
- Python Program to Find all Numbers in a Range which are Perfect Squares and Sum of all Digits in the Number is Less than 10

Advertisements