Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created October 30, 2020 01:14
Show Gist options
  • Save ZechCodes/60ee97a2f572607a5166d2b3560a3e66 to your computer and use it in GitHub Desktop.
Save ZechCodes/60ee97a2f572607a5166d2b3560a3e66 to your computer and use it in GitHub Desktop.
Challenge 142 - Total Volume of All Boxes

Challenge 142 - Total Volume of All Boxes

Given a list of boxes, create a function that returns the total volume of all those boxes combined together. A box is represented by a list with three elements: length, width, and height.

For instance, total_volume([2, 3, 2], [6, 6, 7], [1, 2, 1]) should return 266 since (2 x 3 x 2) + (6 x 6 x 7) + (1 x 2 x 1) = 12 + 252 + 2 = 266.

Examples

total_volume((4, 2, 4), (3, 3, 3), (1, 1, 2), (2, 1, 1)) ➞ 63

total_volume((2, 2, 2), (2, 1, 1)) ➞ 10

total_volume((1, 1, 1)) ➞ 1

Notes

  • You will be given at least one box.
  • Each box will always have three dimensions included.
from __future__ import annotations
import unittest
def total_volume(*boxes: tuple[int, int, int]) -> int:
return 0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(63, total_volume((4, 2, 4), (3, 3, 3), (1, 1, 2), (2, 1, 1)))
def test_2(self):
self.assertEqual(10, total_volume((2, 2, 2), (2, 1, 1)))
def test_3(self):
self.assertEqual(1, total_volume((1, 1, 1)))
def test_4(self):
self.assertEqual(68, total_volume((5, 1, 10), (1, 9, 2)))
def test_5(self):
self.assertEqual(14, total_volume((1, 1, 5), (3, 3, 1)))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment