Васил обнови решението на 17.10.2016 07:49 (преди над 8 години)
+# TODO: Refactor to use Hash
+
+def convert_between_temperature_units(degree, from, to)
+ if from == 'C'
+ if to == 'C'
+ result = degree
+ elsif to == 'F'
+ result = 9.0 / 5 * degree + 32
+ elsif to == 'K'
+ result = degree + 273.15
+ end
+ elsif from == 'F'
+ if to == 'C'
+ result = 5.0 / 9 * (degree - 32)
+ elsif to == 'F'
+ result = degree
+ elsif to == 'K'
+ result = 5.0 / 9 * (degree - 32) + 273.15
+ end
+ elsif from == 'K'
+ if to == 'C'
+ result = degree - 273.15
+ elsif to == 'F'
+ result = 9.0 / 5 * (degree - 273.15) + 32
+ elsif to == 'K'
+ result = degree
+ end
+ end
+ result
+end
+
+def melting_point_of_substance(substance, unit)
+ melting_point = nil
+ if substance == 'water'
+ melting_point = convert_between_temperature_units(0, 'C', unit)
+ elsif substance == 'ethanol'
+ melting_point = convert_between_temperature_units(-114, 'C', unit)
+ elsif substance == 'gold'
+ melting_point = convert_between_temperature_units(1064, 'C', unit)
+ elsif substance == 'silver'
+ melting_point = convert_between_temperature_units(961.8, 'C', unit)
+ elsif substance == 'copper'
+ melting_point = convert_between_temperature_units(1085, 'C', unit)
+ end
+ melting_point
+end
+
+def boiling_point_of_substance(substance, unit)
+ boiling_point = nil
+ if substance == 'water'
+ boiling_point = convert_between_temperature_units(100, 'C', unit)
+ elsif substance == 'ethanol'
+ boiling_point = convert_between_temperature_units(78.37, 'C', unit)
+ elsif substance == 'gold'
+ boiling_point = convert_between_temperature_units(2700, 'C', unit)
+ elsif substance == 'silver'
+ boiling_point = convert_between_temperature_units(2162, 'C', unit)
+ elsif substance == 'copper'
+ boiling_point = convert_between_temperature_units(2567, 'C', unit)
+ end
+ boiling_point
+end