Improve Temperature solution in Scala