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.
This commit is contained in:
Daniel Siepmann 2024-03-25 10:07:22 +01:00
parent 34859ef147
commit 164a2443de
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -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'