Created
October 28, 2014 14:49
-
-
Save Niceblack/1c8e500e0fba33c542d2 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
# python 2.x | |
# Печать всех подмножеств множетсва {1, 2, ..., N} | |
def print_subsets(n, k = 1, s = ""): | |
print "{" + s + "}" # С пустым множеством | |
for i in range(k, n + 1): | |
#print "{" + s + ("," if s else "") + str(i) + "}" # Без пустого множества | |
print_subsets(n, i + 1, s + ("," if s else "") + str(i)) | |
# Использование: | |
print_subsets(4) | |
# Вывод: | |
# {} | |
# {1} | |
# {1,2} | |
# {1,2,3} | |
# {1,2,3,4} | |
# {1,2,4} | |
# {1,3} | |
# {1,3,4} | |
# {1,4} | |
# {2} | |
# {2,3} | |
# {2,3,4} | |
# {2,4} | |
# {3} | |
# {3,4} | |
# {4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment