CoCalc -- Collaborative Calculation in the Cloud
Sharedsage_worksheets / SageMath_assignment.ipynbOpen in CoCalc

Worksheets related to Applied Discrete Structures

# SageMath Assignment : Due June 12 (end of day) ¶

1. Count the number of subsets of the set $\{1,2,3,...,20\}$ whose elements add up to 20. The set can be created with the expression Set(range(1,21)). Here is code for a function the can be used for testing whether a set is to be counted.

def sums_to_20(set):
return sum(set)==20


2. Create SageMath code to do the following:

• Import the csv package
• Read in the States csv file
• For each state, compute its population density (population/area). Use // to compute this number as an integer. Then print the state name followed by the density.

U=Set(range(1,21))

U

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
U.subsets()

Subsets of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
U.subsets()

<bound method Set_object_enumerated_with_category.subsets of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}>
for s in U.subsets():
if 5 in s:
print(s)

{5} {0, 5} {1, 5} {2, 5} {3, 5} {4, 5} {5, 6} {5, 7} {8, 5} {9, 5} {0, 1, 5} {0, 2, 5} {0, 3, 5} {0, 4, 5} {0, 5, 6} {0, 5, 7} {0, 8, 5} {0, 9, 5} {1, 2, 5} {1, 3, 5} {1, 4, 5} {1, 5, 6} {1, 5, 7} {8, 1, 5} {1, 5, 9} {2, 3, 5} {2, 4, 5} {2, 5, 6} {2, 5, 7} {8, 2, 5} {9, 2, 5} {3, 4, 5} {3, 5, 6} {3, 5, 7} {8, 3, 5} {9, 3, 5} {4, 5, 6} {4, 5, 7} {8, 4, 5} {9, 4, 5} {5, 6, 7} {8, 5, 6} {9, 5, 6} {8, 5, 7} {9, 5, 7} {8, 9, 5} {0, 1, 2, 5} {0, 1, 3, 5} {0, 1, 4, 5} {0, 1, 5, 6} {0, 1, 5, 7} {0, 1, 5, 8} {0, 1, 5, 9} {0, 2, 3, 5} {0, 2, 4, 5} {0, 2, 5, 6} {0, 2, 5, 7} {0, 8, 2, 5} {0, 9, 2, 5} {0, 3, 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