Константин обнови решението на 17.10.2016 14:23 (преди около 8 години)
+def convert_between_temperature_units(degrees, measure_from, measure_to)
+ rez = 0
+ if measure_from == "C"
+ if measure_to == "F"
+ rez = (degrees * (9.0 / 5)) + 32
+ elsif measure_to == "K"
+ rez = degrees + 273.15
+ end
+ elsif measure_from == "K"
+ if measure_to == "F"
+ rez = (degrees - 273.15) * (9.0 / 5) + 32
+ elsif measure_to == "C"
+ rez = (degrees - 273.15)
+ elsif measure_to == "K"
+ rez = degrees
+ end
+ elsif measure_from == "F"
+ if measure_to == "C"
+ rez = (degrees - 32) * (5.0 / 9)
+ elsif measure_to == "K"
+ rez = (degrees - 32) * (5.0 / 9) + 273.15
+ elsif measure_to == "F"
+ rez = degrees
+ end
+ end
+ rez
+end
+
+# def boiling_melting(substance, measure, mode)
+# rezult = 0.0
+
+# h = {
+# "water" => [0, 100],
+# "ethanol" => [-114, 78.37],
+# "gold" => [1064, 2700],
+# "silver" => [961.8, 2162],
+# "copper" => [1085, 2567]
+# }
+# if measure == "K" && mode == "melting"
+# rezult = convert_between_temperature_units(h[substance.to_sym][0], "C", "K")
+# elsif measure == "F" && mode == "melting"
+# rezult = convert_between_temperature_units(h[substance.to_sym][0], "C", "F")
+# elsif measure == "C" && mode == "melting"
+# rezult = convert_between_temperature_units(h[substance.to_sym][0], "C", "C")
+# elsif measure == "K" && mode == "boiling"
+# rezult = convert_between_temperature_units(h[substance.to_sym][1], "C", "K")
+# elsif measure == "F" && mode == "boiling"
+# rezult = convert_between_temperature_units(h[substance.to_sym][1], "C", "F")
+# elsif measure == "C" && mode == "boiling"
+# rezult = convert_between_temperature_units(h[substance.to_sym][1], "C", "C")
+# end
+# rezult.round(2)
+# end
+
+def melting_point_of_substance(substance, measure)
+ # boiling_melting(substance, measure, "melting")
+ meltings = {
+ water:
+ {
+ F: convert_between_temperature_units(0, "C", "F"),
+ C: convert_between_temperature_units(0, "C", "C"),
+ K: convert_between_temperature_units(0, "C", "K")
+ },
+ ethanol:
+ {
+ F: convert_between_temperature_units(-114, "C", "F"),
+ C: convert_between_temperature_units(-114, "C", "C"),
+ K: convert_between_temperature_units(-114, "C", "K")
+ },
+ gold:
+ {
+ F: convert_between_temperature_units(1064, "C", "F"),
+ C: convert_between_temperature_units(1064, "C", "C"),
+ K: convert_between_temperature_units(1064, "C", "K")
+ },
+ silver:
+ {
+ F: convert_between_temperature_units(961.8, "C", "F"),
+ C: convert_between_temperature_units(961.8, "C", "C"),
+ K: convert_between_temperature_units(961.8, "C", "K")
+ },
+ copper:
+ {
+ F: convert_between_temperature_units(1085, "C", "F"),
+ C: convert_between_temperature_units(1085, "C", "C"),
+ K: convert_between_temperature_units(1085, "C", "K")
+ }
+ }
+ meltings[substance.to_sym][measure.to_sym].round(2)
+end
+
+def boiling_point_of_substance(substance, measure)
+
+ boiling = {
+ water:
+ {
+ F: convert_between_temperature_units(100.0, "C", "F"),
+ C: 100,
+ K: convert_between_temperature_units(100.0, "C", "K")
+ },
+ ethanol:
+ {
+ F: convert_between_temperature_units(78.37, "C", "F"),
+ C: convert_between_temperature_units(78.37, "C", "C"),
+ K: convert_between_temperature_units(78.37, "C", "K")
+ },
+ gold:
+ {
+ F: convert_between_temperature_units(2700, "C", "F"),
+ C: convert_between_temperature_units(2700, "C", "C"),
+ K: convert_between_temperature_units(2700, "C", "K")
+ },
+ silver:
+ {
+ F: convert_between_temperature_units(2162, "C", "F"),
+ C: convert_between_temperature_units(2162, "C", "C"),
+ K: convert_between_temperature_units(2162, "C", "K")
+ },
+ copper:
+ {
+ F: convert_between_temperature_units(2567, "C", "F"),
+ C: convert_between_temperature_units(2567, "C", "C"),
+ K: convert_between_temperature_units(2567, "C", "K")
+ }
+ }
+ boiling[substance.to_sym][measure.to_sym].round(2)
+end