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

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

Към профила на Станислав Димитров

Резултати

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

Код

def convert_between_temperature_units(temp, current_unit, wanted_unit)
formulas = {
'CK' => temp + 273.15,
'KC' => temp - 273.15,
'CF' => (temp * 1.8) + 32,
'FC' => (temp - 32) / 1.8,
'KF' => (temp * 1.8) - 459.67,
'FK' => (temp + 459.67) / 1.8,
'CC' => temp,
'KK' => temp,
'FF' => temp
}
formulas[current_unit + wanted_unit]
end
puts convert_between_temperature_units(10, 'C', 'K')
def melting_point_of_substance(substance, unit)
substances = {
'water' => 0,
'ethanol' => -114,
'gold' => 1064,
'silver' => 961.8,
'copper' => 1085
}
celsius_melting_point = substances[substance]
convert_between_temperature_units(celsius_melting_point, 'C', unit )
end
def boiling_point_of_substance(substance, unit)
substances = {
'water' => 100,
'ethanol' => 78.37,
'gold' => 2700,
'silver' => 2162,
'copper' => 2567
}
celsius_boiling_point = substances[substance]
convert_between_temperature_units(celsius_boiling_point, 'C', unit )
end

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

283.15
.................

Finished in 0.00818 seconds
17 examples, 0 failures

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

Станислав обнови решението на 17.10.2016 15:13 (преди над 7 години)

+def convert_between_temperature_units(temp, current_unit, wanted_unit)
+ formulas = {
+ 'CK' => temp + 273.15,
+ 'KC' => temp - 273.15,
+ 'CF' => (temp * 1.8) + 32,
+ 'FC' => (temp - 32) / 1.8,
+ 'KF' => (temp * 1.8) - 459.67,
+ 'FK' => (temp + 459.67) / 1.8,
+ 'CC' => temp,
+ 'KK' => temp,
+ 'FF' => temp
+ }
+ units = current_unit + wanted_unit
+ formulas.fetch(units)
+end
+
+def melting_point_of_substance(substance, unit)
+ substances = {
+ 'water' => 0,
+ 'ethanol' => -114,
+ 'gold' => 1064,
+ 'silver' => 961.8,
+ 'copper' => 1085
+ }
+ celsius_melting_point = substances.fetch(substance)
+ convert_between_temperature_units(celsius_melting_point, 'C', unit )
+end
+
+def boiling_point_of_substance(substance, unit)
+ substances = {
+ 'water' => 100,
+ 'ethanol' => 78.37,
+ 'gold' => 2700,
+ 'silver' => 2162,
+ 'copper' => 2567
+ }
+ celsius_boiling_point = substances.fetch(substance)
+ convert_between_temperature_units(celsius_boiling_point, 'C', unit )
+end

Станислав обнови решението на 17.10.2016 15:30 (преди над 7 години)

def convert_between_temperature_units(temp, current_unit, wanted_unit)
- formulas = {
+ formulas = {
'CK' => temp + 273.15,
- 'KC' => temp - 273.15,
+ 'KC' => temp - 273.15,
'CF' => (temp * 1.8) + 32,
'FC' => (temp - 32) / 1.8,
'KF' => (temp * 1.8) - 459.67,
'FK' => (temp + 459.67) / 1.8,
'CC' => temp,
'KK' => temp,
- 'FF' => temp
- }
- units = current_unit + wanted_unit
- formulas.fetch(units)
+ 'FF' => temp
+ }
+ formulas[current_unit + wanted_unit]
end
+puts convert_between_temperature_units(10, 'C', 'K')
+
def melting_point_of_substance(substance, unit)
- substances = {
+ substances = {
'water' => 0,
- 'ethanol' => -114,
+ 'ethanol' => -114,
'gold' => 1064,
'silver' => 961.8,
'copper' => 1085
}
- celsius_melting_point = substances.fetch(substance)
+ celsius_melting_point = substances[substance]
convert_between_temperature_units(celsius_melting_point, 'C', unit )
end
def boiling_point_of_substance(substance, unit)
substances = {
'water' => 100,
'ethanol' => 78.37,
'gold' => 2700,
'silver' => 2162,
'copper' => 2567
}
- celsius_boiling_point = substances.fetch(substance)
+ celsius_boiling_point = substances[substance]
convert_between_temperature_units(celsius_boiling_point, 'C', unit )
end