|
| 1 | +""" |
| 2 | +
|
| 3 | +
|
| 4 | +2026 Winter Games Day 10: Alpine Skiing |
| 5 | +Given a ski hill's vertical drop, horizontal distance, and type, determine the difficulty rating of the hill. |
| 6 | +
|
| 7 | +To determine the rating: |
| 8 | +
|
| 9 | +Calculate the steepness of the hill by taking the drop divided by the distance. |
| 10 | +Then, calculate the adjusted steepness based on the hill type: |
| 11 | +"Downhill" multiply steepness by 1.2 |
| 12 | +"Slalom": multiply steepness by 0.9 |
| 13 | +"Giant Slalom": multiply steepness by 1.0 |
| 14 | +Return: |
| 15 | +
|
| 16 | +"Green" if the adjusted steepness is less than or equal to 0.1 |
| 17 | +"Blue" if the adjusted steepness is greater than 0.1 and less than or equal to 0.25 |
| 18 | +"Black" if the adjusted steepness is greater than 0.25 |
| 19 | +""" |
| 20 | + |
| 21 | +import unittest |
| 22 | + |
| 23 | + |
| 24 | +class AlpineSkiingTest(unittest.TestCase): |
| 25 | + |
| 26 | + def test1(self): |
| 27 | + self.assertEqual(get_hill_rating(620, 2800, "Downhill"), "Black") |
| 28 | + |
| 29 | + def test2(self): |
| 30 | + self.assertEqual(get_hill_rating(420, 1680, "Giant Slalom"), "Blue") |
| 31 | + |
| 32 | + def test3(self): |
| 33 | + self.assertEqual(get_hill_rating(250, 3000, "Downhill"), "Green") |
| 34 | + |
| 35 | + def test4(self): |
| 36 | + self.assertEqual(get_hill_rating(110, 900, "Slalom"), "Blue") |
| 37 | + |
| 38 | + def test5(self): |
| 39 | + self.assertEqual(get_hill_rating(380, 1500, "Giant Slalom"), "Black") |
| 40 | + |
| 41 | + def test6(self): |
| 42 | + self.assertEqual(get_hill_rating(95, 900, "Slalom"), "Green") |
| 43 | + |
| 44 | + |
| 45 | +def get_hill_rating(drop, distance, type): |
| 46 | + |
| 47 | + steepness = drop / distance |
| 48 | + |
| 49 | + if type == "Downhill": |
| 50 | + adjusted = steepness * 1.2 |
| 51 | + elif type == "Slalom": |
| 52 | + adjusted = steepness * 0.9 |
| 53 | + elif type == "Giant Slalom": |
| 54 | + adjusted = steepness * 1.0 |
| 55 | + else: |
| 56 | + raise ValueError("Invalid hill type") |
| 57 | + |
| 58 | + |
| 59 | + if adjusted <= 0.1: |
| 60 | + return "Green" |
| 61 | + elif adjusted <= 0.25: |
| 62 | + return "Blue" |
| 63 | + else: |
| 64 | + return "Black" |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + unittest.main() |
0 commit comments