Skip to content

Instantly share code, notes, and snippets.

@deHelden
Created January 3, 2019 16:40
Show Gist options
  • Save deHelden/6c5050da6b68d9d1af2f8eacd4c904b7 to your computer and use it in GitHub Desktop.
Save deHelden/6c5050da6b68d9d1af2f8eacd4c904b7 to your computer and use it in GitHub Desktop.
[Task 2] Script finds the tallest student in a group
# 2) В одном массиве записан рост некоторых студентов, а в другом
# (с тем же числом элементов) - их фамилии в том же порядке, в котором указан рост.
# Известно, что все студенты разного роста. Напечатайте фамилию самого высокого студента.
def perform
growth = Array.new(6){rand(150..200)}
surname = ["Anderson", "Ashwoon", "Aikin", "Bateman", "Bongard", "Bowers"]
group = surname.zip(growth)
group_h = Hash[group]
highest_growth = group_h.values.max
highest_student = group_h.select{|key, value| value == highest_growth}
highest_student_name = highest_student.keys.first
puts "The highest student (#{highest_growth}) is #{highest_student_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment