|
| 1 | +""" |
| 2 | +
|
| 3 | +2026 Winter Games Day 4: Ski Jumping |
| 4 | +Given distance points, style points, a wind compensation value, and K-point bonus value, calculate your score for the ski jump and determine if you won a medal or not. |
| 5 | +
|
| 6 | +Your score is calculated by summing the above four values. |
| 7 | +The current total scores of the other jumpers are: |
| 8 | +
|
| 9 | +165.5 |
| 10 | +172.0 |
| 11 | +158.0 |
| 12 | +180.0 |
| 13 | +169.5 |
| 14 | +175.0 |
| 15 | +162.0 |
| 16 | +170.0 |
| 17 | +If your score is the best, return "Gold" |
| 18 | +If it's second best, return "Silver" |
| 19 | +If it's third best, return "Bronze" |
| 20 | +Otherwise, return "No Medal" |
| 21 | +""" |
| 22 | + |
| 23 | +import unittest |
| 24 | + |
| 25 | +class SkiJumpingTest(unittest.TestCase): |
| 26 | + |
| 27 | + def test1(self): |
| 28 | + self.assertEqual(ski_jump_medal(125.0, 58.0, 0.0, 6.0), "Gold") |
| 29 | + |
| 30 | + def test2(self): |
| 31 | + self.assertEqual(ski_jump_medal(119.0, 50.0, 1.0, 4.0), "Bronze") |
| 32 | + |
| 33 | + def test3(self): |
| 34 | + self.assertEqual(ski_jump_medal(122.0, 52.0, -1.0, 4.0), "Silver") |
| 35 | + |
| 36 | + def test4(self): |
| 37 | + self.assertEqual(ski_jump_medal(118.0, 50.5, -1.5, 4.0), "No Medal") |
| 38 | + |
| 39 | + def test5(self): |
| 40 | + self.assertEqual(ski_jump_medal(124.0, 50.5, 2.0, 5.0), "Gold") |
| 41 | + |
| 42 | + def test6(self): |
| 43 | + self.assertEqual(ski_jump_medal(119.0, 49.5, 0.0, 3.0), "No Medal") |
| 44 | + |
| 45 | + |
| 46 | +def ski_jump_medal(distance_points, style_points, wind_comp, k_point_bonus): |
| 47 | + |
| 48 | + total_score = distance_points + style_points + wind_comp + k_point_bonus |
| 49 | + |
| 50 | + current_scores = [165.5, 172.0, 158.0, 180.0, 169.5, 175.0, 162.0, 170.0] |
| 51 | + |
| 52 | + current_scores.append(total_score) |
| 53 | + |
| 54 | + current_scores = sorted(current_scores, reverse=True) |
| 55 | + |
| 56 | + if current_scores[0] == total_score: |
| 57 | + return "Gold" |
| 58 | + elif current_scores[1] == total_score: |
| 59 | + return "Silver" |
| 60 | + elif current_scores[2] == total_score: |
| 61 | + return "Bronze" |
| 62 | + else: |
| 63 | + return "No Medal" |
| 64 | + |
| 65 | +""" |
| 66 | +This works fine when your score is unique. but if there's already a jumper with the same score( say 180.0) , then both |
| 67 | +scores are equal. |
| 68 | +
|
| 69 | +Python's sorted() doesn't distinguish between "Yuur 180" and "their 180"- it just places them in order. So you can't tell which 180 belongs to you. |
| 70 | +That means: |
| 71 | +=> If you tie for first, you'll still get "Gold" because your score equals the top value. |
| 72 | +-> But you can't distinguish whether you're the only gold or sharing it. |
| 73 | +=> Same for ties with silver or bronze. |
| 74 | +""" |
| 75 | + |
| 76 | +""" |
| 77 | +
|
| 78 | +If we want to have a solution for the tie breaks as well we need to consider this alternate solution |
| 79 | +=> Adding identifiers: |
| 80 | + Store scores as tuples like ("Me", total_score) and ("other", 180.0). Then when you sort, you can check exactly where "Me" lands. |
| 81 | + -> This lets you distinguish ties, but it complicates the code. |
| 82 | +""" |
| 83 | + |
| 84 | +def ski_jump_medal(distance_points, style_points, wind_comp, k_point_bonus): |
| 85 | + total_score = distance_points + style_points + wind_comp + k_point_bonus |
| 86 | + |
| 87 | + current_scores = [ |
| 88 | + ("Other", 165.5), ("Other", 172.0), ("Other", 158.0), |
| 89 | + ("Other", 180.0), ("Other", 169.5), ("Other", 175.0), |
| 90 | + ("Other", 162.0), ("Other", 170.0), |
| 91 | + ("Me", total_score) |
| 92 | + ] |
| 93 | + |
| 94 | + current_scores.sort(key= lambda x : x[1], reverse=True) |
| 95 | + |
| 96 | + for i, (who, score) in enumerate(current_scores, start=1): |
| 97 | + if who == "Me": |
| 98 | + position = i |
| 99 | + break |
| 100 | + |
| 101 | + if position == 1: |
| 102 | + return "Gold" |
| 103 | + elif position == 2: |
| 104 | + return "Silver" |
| 105 | + elif position == 3: |
| 106 | + return "Bronze" |
| 107 | + else: |
| 108 | + return "No Medal" |
| 109 | + |
| 110 | + |
| 111 | +if __name__ == "__main__": |
| 112 | + unittest.main() |
0 commit comments