Question: Part 2 - Rolling Dice to a Total Given an n - sided die, we want to determine how many different ways one could repeatedly
Part Rolling Dice to a Total
Given an nsided die, we want to determine how many different ways one could repeatedly sum die rolls and
get to a given total.
For instance, given a sided die, we could obtain a total of in four different ways:
rolling a three times
rolling a and then rolling a
rolling a and then rolling a
rolling a
We will write two different functions to solve this problem. Each functions takes the number of sides on
the die and total the total to which we'll sum rolls as input. Each function must use its corresponding
dynamic programming methodology in order to solve the problem.
waystosummemon total
must use memoization
waystosumtabn total
must use tabulation
waystosummemo total
waystosumtab total
FIX THE TABULATION CODE SO IT RETURNS THE CORRECT VALUES. FEEL FREE TO CHANGE ANYTHING ABOUT THE CODE FOR IT TO WORK, JUST MAKE SURE THE CODE USES TABULATION
MY CURRENT CODE:
def waystosumtabn total:
Uses tabulation to determine the number of ways to get the given total with an nsided die"""
# Initialize a table to store subproblem solutions
table total
table
# Fill in the table using previously computed solutions
for i in range n :
for j in rangei total :
tablej tablej i
return tabletotal
TEST CASES FOR THE CODE AND THE EXPECTED RETURNED VALUES FOR EACH TEST
if namemain:
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
printwaystosumtab # Expected value
THE CODES CURRENT VALUES RETURNED FOR THE TESTS:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
