Skip to content

Commit

Permalink
added ThanosSort in python
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmasters authored and ErickSimoes committed Nov 1, 2020
1 parent 47c6e6c commit a9ca3c5
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit a9ca3c5

Please sign in to comment.