Last active
September 9, 2021 14:14
-
-
Save IgorZyktin/a1e3eea9690e4c4d208a8ff938d59a79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from typing import List | |
from typing import MutableSequence | |
from typing import Optional | |
from typing import TypeVar | |
T = TypeVar('T') | |
Sparse = MutableSequence[Optional[T]] | |
MIN = 0.0 | |
MAX = 1000.0 | |
def generate_value(minimum: T, maximum: T) -> T: | |
return random.uniform(minimum, maximum) | |
def fill_array_inplace(array: Sparse, minimum: T, maximum: T) -> None: | |
start = 0 | |
for i in range(0, len(array)): | |
element = array[i] | |
if element is not None: | |
for j in range(start, i): | |
new_value = generate_value(minimum, element) | |
minimum = new_value | |
array[j] = new_value | |
start = i + 1 | |
minimum = max(minimum, element) | |
for k in range(start, len(array)): | |
new_value = generate_value(minimum, maximum) | |
minimum = new_value | |
array[k] = new_value | |
variants: List[Sparse] = [ | |
[None, None, None, None, 7.25, None, None, None, | |
None, 500.0, None, 600.0, None, None, None, None], | |
[None, None, None], | |
[1.0, None, None, None], | |
[None, 2.0, None, None], | |
[None, None, 3.0, None], | |
[1.0, 2.0, 3.0, 4.0], | |
[None, 2.0, None, 4.0, None], | |
] | |
for variant in variants: | |
fill_array_inplace(variant, MIN, MAX) | |
print('---') | |
print(variant) | |
print(sorted(variant)) | |
if variant != sorted(variant): | |
raise ValueError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment