Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Validation</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 500px;
tasks = []
loop do
puts "\n1. Додати задачу"
puts "2. Показати задачі"
puts "3. Видалити задачу"
puts "4. Вийти"
print "\nОберіть опцію: "
choice = gets.chomp
# Task 1: Find the most frequent element(s)
def most_frequent_elements(array)
frequency = Hash.new(0)
array.each { |num| frequency[num] += 1 }
max_freq = frequency.values.max
result = frequency.select { |_, freq| freq == max_freq }.keys
result
# ruby_tasks.rb
# 1. Дано цілочисельний масив. Вивести елементи з парними індексами, а потім з непарними.
data = [1, 2, 3, 4, 5, 6]
p (data.each_with_index.select { |_, i| i.even? } + data.each_with_index.select { |_, i| i.odd? }).map(&:first)
# 2. Дано цілочисельний масив. Вивести елементи з непарними індексами, а потім з парними.
data = [1, 2, 3, 4, 5, 6]
p (data.each_with_index.select { |_, i| i.odd? } + data.each_with_index.select { |_, i| i.even? }).map(&:first)