This file contains 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
def random_numbers(n, range) | |
Array.new(n) { rand(range) } | |
end | |
goals_scored = random_numbers(20, 1..6) | |
goals_missed = random_numbers(20, 1..6) | |
goals_scored.length.times do |i| | |
result = goals_scored[i] - goals_missed[i] | |
if result.positive? |
This file contains 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
require 'faker' | |
def random_names(n) | |
Array.new(n) { Faker::Name.unique.name } | |
end | |
students = random_names(10) | |
height_of_students = (150..200).to_a.sample(10) | |
highest_i = height_of_students.index(height_of_students.max) |
This file contains 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
def random_numbers(n, range) | |
Array.new(n) { rand(range) } | |
end | |
random_array = random_numbers(20, -100..100) | |
min_positive = random_array.select(&:positive?).min | |
array_with_min_positive = random_array.map {|i| i>0 ? min_positive : i} | |
puts "Array: #{random_array.inspect}" | |
puts "Min positive number is #{min_positive}" |
This file contains 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
def random_numbers(n, range) | |
Array.new(n) { rand(range) } | |
end | |
random_array = random_numbers(10, 1..100) | |
cyclic_shift = random_array.rotate | |
puts "Array: #{random_array.inspect}" | |
puts "New Array: #{cyclic_shift}" |
This file contains 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
def random_numbers(n, range) | |
Array.new(n) { rand(range) } | |
end | |
random_array = random_numbers(20, -100..100) | |
array_with_zero = [] | |
#random_array.map { |n| n.positive? ? array_with_zero << 0 << n : array_with_zero << n } | |
random_array.each do |number| | |
if number.positive? |
This file contains 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
def random_numbers(n, range) | |
Array.new(n) { rand(range) } | |
end | |
random_array = random_numbers(20, -100..100) | |
puts "Array: #{random_array.inspect}" | |
puts "New Array: #{random_array.sort}" #{|x,y| x <=> y } optional |
This file contains 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
require 'faker' | |
random_string = Faker::Lorem.words(10).join(" ") #Faker возвращает array, поэтому join в строку | |
sorted_string = random_string.split.sort {|x,y| x.length <=> y.length} | |
puts "String: #{random_string.inspect}" | |
puts "Sorted string: #{sorted_string}" |
This file contains 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
random_string = Faker::Lorem.words(10).join(" ") | |
words = random_string.split.count | |
puts "String: #{random_string.inspect}" | |
puts "Words in string: #{words}" |
This file contains 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
loop do | |
puts "Enter the word you want to check for palindrom words ('example' for example, 'exit' for quite)" | |
word = gets.chomp.downcase.strip | |
break if word == "exit" | |
if word == "example" | |
puts "Word '#{word}' is not a palindrome. Because '#{word}' not equal '#{word.reverse}'" | |
puts "Word 'deified' is a palindrome! Because word 'deified' equally read backwards\n" | |
elsif word == word.reverse |
This file contains 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
# Задача №1 | |
# В одном массиве записано количество мячей, забитых футбольной командой в каждой из 20 игр, | |
# в другом - количество пропущенных мячей в этой же игре. | |
# Для каждой игры определите словесный результат игры (выигрыш, проигрыш или ничью) | |
class Game | |
attr_accessor :scored, :missed, :result | |
def match_result | |
@result = case @scored <=> @missed |
OlderNewer