-
-
Save StaticallyTypedRice/b4503d567e05721c1c5122b70d5ce41b to your computer and use it in GitHub Desktop.
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 | |
'''LICENSE: | |
The MIT License (MIT) | |
Copyright (c) 2019 Richie Zhang | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
''' |
`def find():
a = int(input())
if a%2==0 and a<=16 and a>=1:
x = input()
print(x)
l = splitint(x)
print(l)
p= lcheck(l)
print(p)
r = rcheck(l)
print(r)
return max(p,r)
else:
print("enter the array length correctly")
find()
def lcheck(l):
n = len(l)
m= sorted(l)
if l==m:
return len(l)
else:
n=n//2
l=l[:n-1]
if len(l)>1:
return lcheck(l)
else:
return 1
def rcheck(l):
n = len(l)
m= sorted(l)
if l==m:
return len(l)
else:
n=n//2
l=l[n:]
if len(l)>1:
return rcheck(l)
else:
return 1
def splitint(x):
l = x.split()
l = list(map(int,l))
return l
find()`
this is my attempt... there are many problems in this. But i am tired of giving more time to it.
I've got it in my repo.
@wolfembers The link is broken now. I tried searching the commit history but didn't find it. Was the file deleted or renamed?
Good morning. I removed all the separate files and consolidated them all into the main pixelsort.py file. It is contained as a function in there. Fair warning though, I haven’t updated that side of the repo in a couple years. Expect some errors. Thanks for checking it out though! You’re the first user that’s reached out. Have a good one!
Thank you for the info. And don't worry, I'll be careful!
I'm using this for a picture using Pillow, and I ended up figuring it out using Numpy arrays. I flattened the 3d array for the pixels into a 2d array of (x, y) coordinates for the 3d array, and sampled half of them. If you want to see, I've got it in my repo.