{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

a1solutions

# a1solutions - Assignment 1 Model Solutions CS 234 Fall 2010...

This preview shows pages 1–2. Sign up to view the full content.

## Assignment 1 Model Solutions - CS 234 Fall 2010 ## Note that there are many other acceptable ways to solve these problems. ## These model solutions illustrate more of the design recipe than was ## required. In particular, a sampling of tests are included import math ## test: any any -> boolean ## Consumes two values and prints them for a human to compare. def test(actual, expected): print "Actual value: ", actual, " | Expected value: ", expected ## Question 1 ## total_boxes: int[>=0] int[>=0] int[>=0] int[>=0] -> int[>=0] ## Consumes num_bags, the number of bags to be transported and the number of ## boxes of capacity 10, 8 and 6 bags respectively. Produces the total number of ## boxes needed to transport num_bags by filling the boxes from largest ## capacity to smallest capacity ## Example: total_boxes(1000,50,50,50) => 117 def total_boxes(num_bags, num10, num8, num6): if 10*num10 >= num_bags: return int(math.ceil(num_bags / 10.0)) elif 10*num10 + 8*num8 >= num_bags: return int(num10 + math.ceil((num_bags - 10*num10) / 8.0)) else: return int(num10 + num8 + math.ceil((num_bags - 10*num10 - 8*num8) / 6.0)) test(total_boxes(50,7,7,7),5) test(total_boxes(51,7,7,7),6)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}