Петър обнови решението на 12.10.2016 17:56 (преди около 8 години)
+def convert_between_temperature_units(degrees, base_unit, result_unit)
+ units = "#{base_unit}#{result_unit}"
+
+ case units
+ when "CK" then degrees + 273.15
+ when "CF" then degrees * 9.0 / 5 + 32
+ when "KC" then degrees - 273.15
+ when "KF" then degrees * 9.0 / 5 - 459.67
+ when "FC" then (degrees - 32) * 5.0 / 9
+ when "FK" then (degrees + 495.67) * 5.0 / 9
+ end
+end
+
+def melting_point_of_substance(substance, unit)
+ melting_points_in_celsius = {
+ "water" => 0,
+ "ethanol" => -114,
+ "gold" => 1_064,
+ "silver" => 961.8,
+ "copper" => 1_085
+ }
+
+ if (unit <=> "C") == 0
+ melting_points_in_celsius[substance]
+ else
+ degrees_in_celsius = melting_points_in_celsius[substance]
+ convert_between_temperature_units(degrees_in_celsius, "C", unit)
+ end
+end
+
+def boiling_point_of_substance(substance, unit)
+ boiling_points_in_celsius = {
+ "water" => 100,
+ "ethanol" => 78.37,
+ "gold" => 2_700,
+ "silver" => 2_162,
+ "copper" => 2_567
+ }
+
+ if (unit <=> "C") == 0
+ boiling_points_in_celsius[substance]
+ else
+ degrees_in_celsius = boiling_points_in_celsius[substance]
+ convert_between_temperature_units(degrees_in_celsius, "C", unit)
+ end
+end