Last active
August 29, 2015 14:22
-
-
Save tmehlinger/9f6489ab50cce5e530ac to your computer and use it in GitHub Desktop.
#yolo sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.4 | |
from itertools import tee | |
from random import randint, shuffle | |
import sys | |
def pairwise(iterable): | |
"s -> (s0,s1), (s1,s2), (s2, s3), ..." | |
a, b = tee(iterable) | |
next(b, None) | |
return zip(a, b) | |
def is_sorted(seq): | |
for a, b in pairwise(seq): | |
if a > b: | |
return False | |
return True | |
if __name__ == '__main__': | |
s = [randint(0, 100) for _ in range(int(sys.argv[1]))] | |
print('sequence is', s) | |
shuffle(s) | |
print('"sorted" is', s) | |
msg = '#yolo' | |
if is_sorted(s): | |
msg = '#swag' | |
print(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment