This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#В одном массиве записан рост некоторых студентов, | |
#а в другом (с тем же числом элементов) - их фамилии в том же порядке, в котором указан рост. | |
#Известно, что все студенты разного роста. | |
#Напечатайте фамилию самого высокого студента. | |
array_surname = ["Sidorov", "Petrov", "Ivanov", "Sokolov"] | |
array_rise = [180, 190, 185, 187] | |
puts "Highest boy is #{ array_surname.at( array_rise.index( array_rise.max ) ) } with rise a #{ array_rise.max } cm " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#В одном массиве записано количество мячей, забитых футбольной командой в | |
#каждой из 20 игр, в другом - количество пропущенных мячей в этой же игре. | |
#Для каждой игры определите словесный результат игры (выигрыш, проигрыш или ничью) | |
balls_missed = [1, 2, 3, 1, 1, 2] | |
balls_scored = [1, 4, 1, 1, 2, 1] | |
balls_missed.each_with_index do |i, index| | |
count_missed = balls_missed.at(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# В одном массиве записан рост некоторых студентов, а в другом (с тем же числом элементов) - | |
# их фамилии в том же порядке, в котором указан рост. Известно, что все студенты разного роста. | |
# Напечатайте фамилию самого высокого студента. | |
class Group | |
NAME_TEMPLATE = ['Кашин','Маваши', 'Дубовик', 'Кашин', 'Какашин', 'Малевич', 'Чернышев', 'Криштопчик', 'Клицунова', 'Чеховский', 'Дорогокупец', 'Рак', 'Трофимов'] | |
def initialize(n) | |
@heights = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sort_array | |
def initialize | |
@numbers = [0, 4, 2, 6, 1, 9, 5, 8, 3, 7] | |
end | |
def self.run | |
new.run | |
end | |
def run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Move_left | |
def initialize | |
@numbers = [1, 2, 3, 4, 5, 6] | |
end | |
def self.run | |
new.run | |
end | |
def run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Дана строка в которой записаны слова через пробел. Необходимо посчитать количество слов. | |
s = "This is a string with seven words" | |
puts s.split.size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Дана строка в которой записаны слова через пробел. | |
# Необходимо упорядочить слова по количеству букв в каждом слове. | |
str = "mother father ruby exhibition railway smartphone" | |
str = str.split.sort_by!(&:length).join(" ") | |
puts str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Дан целочисленный массив. Упорядочить его по возрастанию. | |
arr = [1, 5, 4, 2, 3, 7, 6, 8, 10, 9] | |
arr.sort! | |
puts arr.to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Дан целочисленный массив. Преобразовать его, вставив перед каждым положительным элементом нулевой элемент. | |
arr = [1, 2, -2, 10, -24, 5, 6, 7, -9, -1] | |
new_arr = arr.map { |e| e > 0 ? [arr[0], e] : e } | |
new_arr.flatten! | |
puts new_arr.to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Дан целочисленный массив. Осуществить циклический сдвиг элементов массива влево на одну позицию. | |
arr = [1, 2, 3, 4, 5, 6, 7] | |
arr.rotate! | |
# or | |
# arr.push(arr.shift) | |
# or |