1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-11-09 22:08:58 +01:00

feat(solutions): add consecutive-numbers/python/function

This commit is contained in:
Divlo 2021-06-28 20:15:35 +02:00
parent 8eae4313a9
commit 5b2b72df16
No known key found for this signature in database
GPG Key ID: 185ED2F15F104E52
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# consecutive-numbers/python/function
Created by [@Divlo](https://github.com/Divlo) on 28 June 2021.

View File

@ -0,0 +1,26 @@
from typing import List
import sys
input_values: List[str] = []
for value in sys.stdin:
input_values.append(value.rstrip('\n'))
def consecutive_numbers(numbers: List[int]) -> List[List[int]]:
consecutive_numbers_pairs: List[List[int]] = []
numbers_length = len(numbers)
for index in range(numbers_length):
number = numbers[index]
is_last_number = index == numbers_length - 1
if not is_last_number and number + 1 == numbers[index + 1]:
consecutive_numbers_pairs.append([number, number + 1])
return consecutive_numbers_pairs
numbers: List[int] = []
for value in input_values:
numbers.append(int(value))
consecutive_numbers_pairs = consecutive_numbers(numbers)
for pairs in consecutive_numbers_pairs:
print(f"{pairs[0]} ; {pairs[1]}")