Created
November 21, 2014 02:01
-
-
Save mitchellhuang/ecb25d03f3be18ad2535 to your computer and use it in GitHub Desktop.
proj4 q19 doeeeeee
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
def partitions(n, m): | |
"""Return a linked list of partitions | |
of n using parts of up to m. | |
Each partition is a linked list. | |
""" | |
if n == 0: | |
return link(empty, empty) | |
elif n < 0: | |
return empty | |
elif m == 0: | |
return empty | |
else: | |
# Do I use at least one m? | |
yes = partitions(n-m, m) | |
no = partitions(n, m-1) | |
add_m = lambda s: link(m, s) | |
yes = apply_to_all_link(add_m, yes) | |
return extend(yes, no) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment