Решение на Първа задача - температура и химични елементи от Милен Дончев

Обратно към всички решения

Към профила на Милен Дончев

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 17 успешни тест(а)
  • 0 неуспешни тест(а)

Код

CELSIUS = 'C'
FAHRENHEIT = 'F'
KELVIN = 'K'
MELTING_POINTS_CELSIUS = {
'water' => 0,
'ethanol' => -114,
'gold' => 1064,
'silver' => 961.8,
'copper' => 1085,
}
BOILING_POINTS_CELSIUS = {
'water' => 100,
'ethanol' => 78.37,
'gold' => 2700,
'silver' => 2162,
'copper' => 2567,
}
def convert_between_temperature_units(degrees, from_unit, to_unit)
return degrees if from_unit == to_unit
if from_unit == CELSIUS && to_unit == FAHRENHEIT
(degrees * 1.8) + 32
elsif from_unit == CELSIUS && to_unit == KELVIN
degrees + 273.15
elsif from_unit == FAHRENHEIT && to_unit == CELSIUS
(degrees - 32) / 1.8
elsif from_unit == FAHRENHEIT && to_unit == KELVIN
(degrees + 459.67) * 5 / 9
elsif from_unit == KELVIN && to_unit == CELSIUS
degrees - 273.15
elsif from_unit == KELVIN && to_unit == FAHRENHEIT
(degrees * 9 / 5) - 459.67
end
end
def melting_point_of_substance(substance, unit)
degrees = MELTING_POINTS_CELSIUS[substance]
convert_between_temperature_units(degrees, CELSIUS, unit)
end
def boiling_point_of_substance(substance, unit)
degrees = BOILING_POINTS_CELSIUS[substance]
convert_between_temperature_units(degrees, CELSIUS, unit)
end

Лог от изпълнението

.................

Finished in 0.00775 seconds
17 examples, 0 failures

История (2 версии и 0 коментара)

Милен обнови решението на 16.10.2016 22:31 (преди около 8 години)

+CELSIUS = 'C'
+FAHRENHEIT = 'F'
+KELVIN = 'K'
+
+MELTING_POINTS_CELSIUS = {
+ 'water' => 0,
+ 'ethanol' => -114,
+ 'gold' => 1064,
+ 'silver' => 961.8,
+ 'copper' => 1085,
+}
+
+BOILING_POINTS_CELSIUS = {
+ 'water' => 100,
+ 'ethanol' => 78.37,
+ 'gold' => 2700,
+ 'silver' => 2162,
+ 'copper' => 2567,
+}
+
+def convert_between_temperature_units(degrees, from_unit, to_unit)
+ return degrees if from_unit == to_unit
+
+ if from_unit == CELSIUS && to_unit == FAHRENHEIT
+ (degrees * 1.8) + 32
+ elsif from_unit == CELSIUS && to_unit == KELVIN
+ degrees + 273.15
+ elsif from_unit == FAHRENHEIT && to_unit == CELSIUS
+ (degrees - 32) / 1.8
+ elsif from_unit == FAHRENHEIT && to_unit == KELVIN
+ (degrees + 459.67) * (5 / 9)
+ elsif from_unit == KELVIN && to_unit == CELSIUS
+ degrees - 273.15
+ elsif from_unit == KELVIN && to_unit == FAHRENHEIT
+ degrees * (9 / 5) - 459.67
+ end
+end
+
+def melting_point_of_substance(substance, unit)
+ degrees = MELTING_POINTS_CELSIUS[substance]
+ convert_between_temperature_units(degrees, CELSIUS, unit)
+end
+
+def boiling_point_of_substance(substance, unit)
+ degrees = BOILING_POINTS_CELSIUS[substance]
+ convert_between_temperature_units(degrees, CELSIUS, unit)
+end

Милен обнови решението на 16.10.2016 22:48 (преди около 8 години)

CELSIUS = 'C'
FAHRENHEIT = 'F'
KELVIN = 'K'
MELTING_POINTS_CELSIUS = {
'water' => 0,
'ethanol' => -114,
'gold' => 1064,
'silver' => 961.8,
'copper' => 1085,
}
BOILING_POINTS_CELSIUS = {
'water' => 100,
'ethanol' => 78.37,
'gold' => 2700,
'silver' => 2162,
'copper' => 2567,
}
def convert_between_temperature_units(degrees, from_unit, to_unit)
return degrees if from_unit == to_unit
-
+
if from_unit == CELSIUS && to_unit == FAHRENHEIT
(degrees * 1.8) + 32
elsif from_unit == CELSIUS && to_unit == KELVIN
degrees + 273.15
elsif from_unit == FAHRENHEIT && to_unit == CELSIUS
(degrees - 32) / 1.8
elsif from_unit == FAHRENHEIT && to_unit == KELVIN
- (degrees + 459.67) * (5 / 9)
+ (degrees + 459.67) * 5 / 9
elsif from_unit == KELVIN && to_unit == CELSIUS
degrees - 273.15
elsif from_unit == KELVIN && to_unit == FAHRENHEIT
- degrees * (9 / 5) - 459.67
+ (degrees * 9 / 5) - 459.67
end
end
def melting_point_of_substance(substance, unit)
degrees = MELTING_POINTS_CELSIUS[substance]
convert_between_temperature_units(degrees, CELSIUS, unit)
end
def boiling_point_of_substance(substance, unit)
degrees = BOILING_POINTS_CELSIUS[substance]
convert_between_temperature_units(degrees, CELSIUS, unit)
end