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

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

Към профила на Добромира Лозева

Резултати

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

Код

def convert_between_temperature_units(deg, from, to)
deg += 273.15 if from == 'C' && to == 'K'
deg if from == to
deg = (deg * 1.8) + 32 if from == 'C' && to == 'F'
deg -= 273.15 if from == 'K' && to == 'C'
deg = (deg * 1.8) - 459.67 if from == 'K' && to == 'F'
deg = (deg - 32) * 0.55555555555 if from == 'F' && to == 'C'
deg = (deg + 459.67) * 0.55555555555 if from == 'F' && to == 'K'
deg
end
BOILING = {
'water' => 100,
'ethanol' => 78.37,
'gold' => 2700,
'silver' => 2162,
'copper' => 2567
}
MELTING = {
'water' => 0,
'ethanol' => -114,
'gold' => 1064,
'silver' => 961.8,
'copper' => 1085,
}
def boiling_point_of_substance(substance, type_of_deg)
convert_between_temperature_units(BOILING[substance], 'C', type_of_deg)
end
def melting_point_of_substance(substance, type_of_deg)
convert_between_temperature_units(MELTING[substance], 'C', type_of_deg)
end

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

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

Finished in 0.00841 seconds
17 examples, 0 failures

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

Добромира обнови решението на 17.10.2016 00:13 (преди над 7 години)

+def convert_between_temperature_units(deg, from, to)
+ deg += 273.15 if from == 'C' && to == 'K'
+ deg if from == to
+ deg = (deg * 1.8) + 32 if from == 'C' && to == 'F'
+ deg -= 273.15 if from == 'K' && to == 'C'
+ deg = (deg * 1.8) - 459.67 if from == 'K' && to == 'F'
+ deg = (deg - 32) * 0.55555555555 if from == 'F' && to == 'C'
+ deg = (deg + 459.67) * 0.55555555555 if from == 'F' && to == 'K'
+
+ deg
+
+end
+
+BOILING = {
+ 'water' => 100,
+ 'ethanol' => 78.37,
+ 'gold' => 2700,
+ 'silver' => 2162,
+ 'copper' => 2567
+}
+
+MELTING = {
+ 'water' => 0,
+ 'ethanol' => -114,
+ 'gold' => 1064,
+ 'silver' => 961.8,
+ 'copper' => 1085,
+}
+
+def boiling_point_of_substance(substance, type_of_deg)
+ convert_between_temperature_units(BOILING[substance], 'C', type_of_deg)
+end
+
+def melting_point_of_substance(substance, type_of_deg)
+ convert_between_temperature_units(MELTING[substance], 'C', type_of_deg)
+end