Created
August 19, 2015 11:44
-
-
Save wolph/17552c9508753044e44f to your computer and use it in GitHub Desktop.
Quicksort using the Y Combinator (lambda calculus) in pure Python
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
# Quicksort using the Y Combinator (lambda calculus) in pure Python | |
>>> Y = lambda f: lambda *args: f(Y(f))(*args) | |
>>> quicksort = Y(lambda f: | |
... lambda x: ( | |
... f([item for item in x if item < x[0]]) | |
... + [y for y in x if x[0] == y] | |
... + f([item for item in x if item > x[0]]) | |
... ) if x else []) | |
>>> quicksort([1, 3, 5, 4, 1, 3, 2]) | |
[1, 1, 2, 3, 3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment