Skip to content

Instantly share code, notes, and snippets.

@TomLisankie
Created March 15, 2022 01:06
Show Gist options
  • Save TomLisankie/61a4606af5c3081dc866d735e3a5705c to your computer and use it in GitHub Desktop.
Save TomLisankie/61a4606af5c3081dc866d735e3a5705c to your computer and use it in GitHub Desktop.
from random import randint
def random_8_unique_ints_seq():
nums = []
while len(nums) < 8:
new_num = randint(1, 8)
if new_num not in nums:
nums.append(new_num)
return nums
def four_sort(arr):
assert len(arr) == 4
return sorted(arr)
def the_whole_process(initial_seq):
first_four = initial_seq[:4]
last_four = initial_seq[4:]
first_four_sorted = four_sort(first_four)
last_four_sorted = four_sort(last_four)
smallest_of_each = first_four_sorted[:2] + last_four_sorted[:2]
smallest_sorted = four_sort(smallest_of_each)
largest_of_each = first_four_sorted[2:] + last_four_sorted[2:]
largest_sorted = four_sort(largest_of_each)
beginning = smallest_sorted[:2]
end = largest_sorted[2:]
middle = smallest_sorted[2:] + largest_sorted[:2]
middle_sorted = four_sort(middle)
final_seq = beginning + middle_sorted + end
print(final_seq)
return final_seq == [1, 2, 3, 4, 5, 6, 7, 8]
print(the_whole_process(random_8_unique_ints_seq()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment