Skip to content

Commit

Permalink
Counting Subsets
Browse files Browse the repository at this point in the history
  • Loading branch information
jdp committed Apr 13, 2013
1 parent b654c81 commit 9c637db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Empty file added sset/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions sset/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

"""
Given: A positive integer n (n≤1000).
Return: The total number of subsets of {1,2,…,n} modulo 1,000,000.
>>> problem(3)
8
"""

from ..util import binomial


def problem(n):
return sum([binomial(n, i) for i in range(n + 1)]) % 1000000


if __name__ == '__main__':
import doctest
from os.path import dirname

doctest.testmod()

n = int(open(dirname(__file__) + "/rosalind_sset.txt").read().strip())
print problem(n)
1 change: 1 addition & 0 deletions sset/rosalind_sset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
835

0 comments on commit 9c637db

Please sign in to comment.