From 164a2443deaf928e63494e6a1b44d0e2d619ff10 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 25 Mar 2024 10:07:22 +0100 Subject: [PATCH] Solve python/exercises/meltdown-mitigation With help of https://exercism.org/tracks/python/exercises/meltdown-mitigation/solutions/adbeep as I didn't understand the math and logic behind the +/- 10% instruction. --- python/meltdown-mitigation/conditionals.py | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/python/meltdown-mitigation/conditionals.py b/python/meltdown-mitigation/conditionals.py index 1eb0a57..32bd5db 100644 --- a/python/meltdown-mitigation/conditionals.py +++ b/python/meltdown-mitigation/conditionals.py @@ -14,7 +14,7 @@ def is_criticality_balanced(temperature, neutrons_emitted): - The product of temperature and neutrons emitted per second is less than 500000. """ - pass + return temperature < 800 and neutrons_emitted > 500 and (temperature * neutrons_emitted) < 500000 def reactor_efficiency(voltage, current, theoretical_max_power): @@ -37,7 +37,17 @@ def reactor_efficiency(voltage, current, theoretical_max_power): where generated power = voltage * current """ - pass + generated_power = voltage * current + percentage = (generated_power / theoretical_max_power) * 100 + + if percentage >= 80: + return 'green' + if percentage >= 60: + return 'orange' + if percentage >= 30: + return 'red' + + return 'black' def fail_safe(temperature, neutrons_produced_per_second, threshold): @@ -53,4 +63,13 @@ def fail_safe(temperature, neutrons_produced_per_second, threshold): 3. 'DANGER' -> `temperature * neutrons per second` is not in the above-stated ranges """ - pass + low_threshold = 90/100 * threshold + high_threshold = ((10/100)+(100/100)) * threshold + value = temperature * neutrons_produced_per_second + + if value <= low_threshold: + return 'LOW' + if value >= low_threshold and value <= high_threshold: + return 'NORMAL' + + return 'DANGER'