Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ThanosSort in python #820

Merged
merged 1 commit into from
Nov 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ThanosSort/ThanosSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import random
import typing.List

def thanos_sort(a: List[int]) -> List[int]:
'''Removes half of the list until it's perfectly balanced, like all things should be.'''

def _perfectly_balanced(a: List[int]) -> bool:

like_all_things_should_be = True

for i in range(1, len(a)):
if a[i] < a[i-1]:
like_all_things_should_be = False
break

return like_all_things_should_be

def _snap(a: List[int]) -> List[int]:

numbers_that_dont_feel_so_good = random.sample(range(len(a)), round(len(a)/2, 0))

b = []
for i in range(len(a)):
if i not in numbers_that_dont_feel_so_good:
b.append(a[i])

return b

while not _perfectly_balanced(a):
a = _snap(a)

return a