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

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

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

Резултати

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

Код

def convert_between_temperature_units(degree, input, output)
if input == output
degree
elsif input == 'C' && output == 'F'
degree * 1.8 + 32
elsif input == 'C' && output == 'K'
degree + 273.15
elsif input == 'K' && output == 'F'
degree * 9 / 5 - 459.67
elsif input == 'K' && output == 'C'
degree - 273.15
elsif input == 'F' && output == 'C'
(degree - 32) / 1.8
elsif input == 'F' && output == 'K'
(degree + 459.67) * 5 / 9
end
end
def melting_point_of_substance(element, measure)
elements_melt = {'water' => 0, 'ethanol' => -114, 'gold' => 1064, 'silver' => 961.8, 'copper' => 1085}
convert_between_temperature_units(elements_melt[element], 'C', measure)
end
def boiling_point_of_substance(element, measure)
elements_boil = {'water' => 100, 'ethanol' => 78.37, 'gold' => 2700, 'silver' => 2162, 'copper' => 2567}
convert_between_temperature_units(elements_boil[element], 'C', measure)
end

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

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

Finished in 0.00774 seconds
17 examples, 0 failures

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

Стамен обнови решението на 16.10.2016 12:16 (преди около 8 години)

+def convert_between_temperature_units(degree, input, output)
+ if input == output
+ degree
+ elsif input == 'C' && output == 'F'
+ degree * 1.8 + 32
+ elsif input == 'C' && output == 'K'
+ degree + 273.15
+ elsif input == 'K' && output == 'F'
+ degree * 9 / 5 - 459.67
+ elsif input == 'K' && output == 'C'
+ degree - 273.15
+ elsif input == 'F' && output == 'C'
+ (degree - 32) / 1.8
+ elsif input == 'F' && output == 'K'
+ (degree + 459.67) * 5 / 9
+ end
+end
+
+def melting_point_of_substance(element, measure)
+ if element == 'water'
+ convert_between_temperature_units(0, 'C', measure)
+ elsif element == 'ethanol'
+ convert_between_temperature_units(-114, 'C', measure)
+ elsif element == 'gold'
+ convert_between_temperature_units(1064, 'C', measure)
+ elsif element == 'silver'
+ convert_between_temperature_units(961.8, 'C', measure)
+ elsif element == 'copper'
+ convert_between_temperature_units(1085, 'C', measure)
+ end
+end
+
+def boiling_point_of_substance(element, measure)
+ if element == 'water'
+ convert_between_temperature_units(100, 'C', measure)
+ elsif element == 'ethanol'
+ convert_between_temperature_units(78.37, 'C', measure)
+ elsif element == 'gold'
+ convert_between_temperature_units(2700, 'C', measure)
+ elsif element == 'silver'
+ convert_between_temperature_units(2162, 'C', measure)
+ elsif element == 'copper'
+ convert_between_temperature_units(2567, 'C', measure)
+ end
+end

Стамен обнови решението на 16.10.2016 16:27 (преди около 8 години)

def convert_between_temperature_units(degree, input, output)
if input == output
degree
elsif input == 'C' && output == 'F'
degree * 1.8 + 32
elsif input == 'C' && output == 'K'
degree + 273.15
elsif input == 'K' && output == 'F'
degree * 9 / 5 - 459.67
elsif input == 'K' && output == 'C'
degree - 273.15
elsif input == 'F' && output == 'C'
(degree - 32) / 1.8
elsif input == 'F' && output == 'K'
(degree + 459.67) * 5 / 9
end
end
def melting_point_of_substance(element, measure)
- if element == 'water'
- convert_between_temperature_units(0, 'C', measure)
- elsif element == 'ethanol'
- convert_between_temperature_units(-114, 'C', measure)
- elsif element == 'gold'
- convert_between_temperature_units(1064, 'C', measure)
- elsif element == 'silver'
- convert_between_temperature_units(961.8, 'C', measure)
- elsif element == 'copper'
- convert_between_temperature_units(1085, 'C', measure)
- end
+ elements_melt = {'water' => 0, 'ethanol' => -114, 'gold' => 1064, 'silver' => 961.8, 'copper' => 1085}
+ convert_between_temperature_units(elements_melt[element], 'C', measure)
end
def boiling_point_of_substance(element, measure)
- if element == 'water'
- convert_between_temperature_units(100, 'C', measure)
- elsif element == 'ethanol'
- convert_between_temperature_units(78.37, 'C', measure)
- elsif element == 'gold'
- convert_between_temperature_units(2700, 'C', measure)
- elsif element == 'silver'
- convert_between_temperature_units(2162, 'C', measure)
- elsif element == 'copper'
- convert_between_temperature_units(2567, 'C', measure)
- end
+ elements_boil = {'water' => 100, 'ethanol' => 78.37, 'gold' => 2700, 'silver' => 2162, 'copper' => 2567}
+ convert_between_temperature_units(elements_boil[element], 'C', measure)
end