Here's a useful mnemonic for remembering how to convert Celsius to Fahrenhait(*):
- Start at 4°C
- Add +12 each time
- Flip the C in mirror, with some additional fudging
For example, 4°C is 04°C. Mirror image of "04" is "40". So 4°C equals 40°F.
And when there's a 1 in front, as in 125°F, look at that as 100 + 25°F. Mirror of 25°F is 52°C. So 52°C equals 125°F.
In Python it can be tested like this:
import math
def c2f(c):
return c * 9 / 5 + 32
def is_mirror(a, b):
def massage(n):
if n < 10:
return f"0{n}"
elif n >= 100:
return massage(n - 100)
else:
return str(n)
return massage(a)[::-1] == massage(b)
def print_conv(c, f):
print(f"{c}°C ~= {f}°F")
for i in range(4, 100, 12):
f = c2f(i)
if is_mirror(i, math.ceil(f)):
print_conv(i, math.ceil(f))
elif is_mirror(i, math.floor(f)):
print_conv(i, math.floor(f))
else:
break
When you run that you get:
4°C ~= 40°F 16°C ~= 61°F 28°C ~= 82°F 40°C ~= 104°F 52°C ~= 125°F
(*) If you can't remember F = C × 9/5 + 32 or, perhaps, remember it but can't compute the arithmetic easily.
Comments