![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 23.04.2021 16:10 Vamoppppp
Counting
This third python programming assignment, PA3, is about counting. You will write two functions partitions(n, k) that counts in how many ways n distinct elements can be grouped into k (non empty) partitions, and mkCh(a, c) that counts in how many ways amount a can be paid with coins {1,5,10,25}. Both algorithms are discussed in lecture 15: counting. Start with the skeleton code. A correct implementation of counting:
python3 counting. py 3 2
produces
n: 3 k: 2 partitions: 3
amount: 32 coins: [1, 5, 10, 25] ways: 18
counting. txt
import sys
coins = [1,5,10,25]
def partitions(n, k):
"""
pre 00
post return the number of ways k partitions
can be formed out of n distinct elements
"""
# if k==n or k==1 :
# there is only one way to form partitions
# else :
# select an element a, and
# either
# form k partitions with the rest of the elements
# and let a join one of these k groups
# or
# let a form its own partition, and
# form k-1 partitions with the rest
return 1
def mkCh(a, c):
"""
given coin set {1,5,10,25} count how many ways we can pay amount a,
c indicates which coin is considered first. c starts as the index
of the last coin value (len(coins)-1)
"""
return 1
if __name__ == "__main__":
# partititions
d = len(sys. argv)>3
n = int(sys. argv[1])
k = int(sys. argv[2])
p = partitions(n, k)
print("n:",n,"k:",k, "partitions:",p)
# make change
c = len(coins)-1
a = 10*n+k
ways = mkCh(a, c)
print("amount:", a, "coins:", coins, "ways:", ways)
![ansver](/tpl/images/cats/User.png)
Answers: 2
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Another question on Computers and Technology
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 10:40
When running anti-virus software , what could be a reason where recipitent is not guaranteed that data being streamed will not get interrupted?
Answers: 1
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 18:00
When is it appropriate to use an absolute reference
Answers: 1
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 20:00
Which location-sharing service offers items for users as a gaming component and also allows them to collectively link their check-ins to publish a trip? a. whrrl b. buzzd c. foursquare (this option is wrong i already tried) d. gowalla for plato
Answers: 2
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 09:30
Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks are greater than rewards. ( need )
Answers: 1
You know the right answer?
Counting
This third python programming assignment, PA3, is about counting. You will write two func...
Questions
![question](/tpl/images/cats/fr.png)
French, 15.12.2020 21:20
![question](/tpl/images/cats/obshestvoznanie.png)
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 15.12.2020 21:20
![question](/tpl/images/cats/himiya.png)
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/obshestvoznanie.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 15.12.2020 21:20
![question](/tpl/images/cats/mat.png)
Mathematics, 15.12.2020 21:20
![question](/tpl/images/cats/mat.png)
Mathematics, 15.12.2020 21:20
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 15.12.2020 21:20
![question](/tpl/images/cats/himiya.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 15.12.2020 21:20
![question](/tpl/images/cats/fizika.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 15.12.2020 21:20