Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created November 1, 2020 02:13
Show Gist options
  • Save ZechCodes/72e4b9f8734c33cd9fd9b96e3fc698f4 to your computer and use it in GitHub Desktop.
Save ZechCodes/72e4b9f8734c33cd9fd9b96e3fc698f4 to your computer and use it in GitHub Desktop.
Challenge 144 - Snail Goes Up the Stairs

Challenge 144 - Snail Goes Up the Stairs

A snail goes up the stairs. Every step, he must go up the step, then go across to the next step. He wants to reach the top of the tower.

Write a function that returns the distance the snail must travel to the top of the tower given the height and length of each step and the height of the tower.

Examples

total_distance(0.2, 0.4, 100.0) ➞ 300.0
# Total distance is 300.

total_distance(0.3, 0.2, 25.0) ➞ 41.7

total_distance(0.1, 0.1, 6.0) ➞ 12.0

Notes

  • All given values are greater than 0.
  • Round answers to the nearest tenth 0.1.
  • Number of steps determined by tower height divided by stair height.

For the purposes of this exercise, the last step's length must be counted to complete the journey.

import unittest
def total_distance(height: float, length: float, tower_height: float) -> float:
return 0.0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(300.0, total_distance(0.2, 0.4, 100.0))
def test_2(self):
self.assertEqual(18.3, total_distance(0.12, 0.1, 10.0))
def test_3(self):
self.assertEqual(50.0, total_distance(0.5, 0.5, 25.0))
def test_4(self):
self.assertEqual(12.0, total_distance(0.1, 0.1, 6.0))
def test_5(self):
self.assertEqual(3.3, total_distance(0.05, 0.1, 1.1))
def test_6(self):
self.assertEqual(1554.0, total_distance(1.0, 1.0, 777.0))
def test_7(self):
self.assertEqual(150.9, total_distance(0.2, 0.1, 100.6))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment