a1solutions

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

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

View Full Document Right Arrow Icon
## 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))
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online