Vekked the sort of vekk sort

This commit is contained in:
2018-12-11 21:08:47 +01:00
parent 0c7b1b60ac
commit e90edcc55d
4 changed files with 1000053 additions and 1 deletions

23
luke_01/vekksorrt.py Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env python3
def fileContents(path='./input-vekksort.txt'):
import os
path = os.path.join(os.path.dirname(__file__), path)
with open(path, 'r') as f:
return f.read().split('\n')[:-1]
def vekk(numbers):
vekked = []
lastLarger = lambda curr, prev: int(curr) >= int(prev)
for i, num in enumerate(numbers):
if (i == 0 or lastLarger(num, vekked[-1])):
vekked.append(int(num))
return sum(vekked)
def main():
return vekk(fileContents())
if __name__ == '__main__':
print(main())