misc: add more scripts

This commit is contained in:
2020-11-05 16:31:14 +01:00
parent afd306ad06
commit 6c1248e814
11 changed files with 2481 additions and 0 deletions

25
misc/sort.py Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env python3
import sys
def insertion_sort(arr, compare=lambda x, y: x < y):
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while compare(key, arr[j]):
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
return arr
def manual_compare(x, y):
reply = input("{} <= {} (y/n)? ".format(x, y))
return reply.lower() == "y"
if __name__ == "__main__":
lines = sys.argv[1:]
sorted_lines = insertion_sort(lines, manual_compare)
for i, line in enumerate(lines):
print(i + 1, line)