subject

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
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 06:00, hilarydodard7099
Which statistical function in a spreadsheet you to see how far each number varies, on average, from the average value of the list?
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, bubbles173883
While inserting images, the picture command is usually used to insert photos from a digital camera, and the clip art command is usually used to a. edit the sizes and other characteristics of photos that have been inserted. b. take a screenshot of an image and copy it to the clipboard for pasting. c. search for drawings or other images from a library of prepared pictures. d. make illustrations using lines and shapes that are easy to manipulate.
Answers: 1
image
Computers and Technology, 24.06.2019 02:10, trint5952
Aspeed limit sign that says "night" indicates the legal speed between sunset and sunrise.
Answers: 2
image
Computers and Technology, 25.06.2019 08:50, JadeCaldwell
A-12.3 an american spy is deep undercover in the hostile country of phonemia. in order not to waste scarce resources, any time he wants to send a message back home, he removes all the punctuation from his message and converts all the letters to uppercase. so, for example, to send the message, “abort the plan! meet at the dark cabin.” he would transmit given such a string, s, of n uppercase letters, describe an efficient way of breaking it into a sequence of valid english words. you may assume that you have a function, valid(s), which can take a character string, s, and return true if and only if s is a valid english word. what is the running time of your algorithm, assuming each call to the function, valid, runs in o(1) time?
Answers: 3
You know the right answer?
Counting This third python programming assignment, PA3, is about counting. You will write two func...

Questions in other subjects:

Konu
Mathematics, 19.07.2020 05:01
Konu
Mathematics, 19.07.2020 05:01
Konu
English, 19.07.2020 05:01
Konu
Mathematics, 19.07.2020 05:01
Konu
Business, 19.07.2020 05:01
Konu
Spanish, 19.07.2020 05:01