feat: add prime_divisors function to retrieve prime divisors of a number

lab3
Artem-Darius Weber 1 month ago
parent b9453a87e8
commit f015f43c99

@ -43,6 +43,12 @@ def minimal_even_element(array)
end
def prime_divisors(number)
require 'prime'
(2..number).select { |x| number % x == 0 && Prime.prime?(x) }
end
# Ex
array = [5, 3, 8, 1, 7]
puts "Indices in order of decreasing elements:"
@ -59,3 +65,7 @@ puts elements_between_first_and_last_max(array).join(", ")
array = [5, 2, 8, 3, 7]
puts "Minimal even element:"
puts minimal_even_element(array)
number = 28
puts "Prime divisors:"
puts prime_divisors(number).join(", ")

Loading…
Cancel
Save