End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Prime#int_from_prime_division
int_from_prime_division(pd)
lib/prime.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/prime.rb, line 268
def int_from_prime_division(pd)
pd.inject(1){|value, (prime, index)|
value * prime**index
}
end
Re-composes a prime factorization and returns the product.
For the decomposition:
[[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]],
it returns:
p_1**e_1 * p_2**e_2 * ... * p_n**e_n.
Parameters
pd-
Arrayof pairs of integers. Each pair consists of a prime number – a prime factor – and a natural number – its exponent (multiplicity).
Example
Example
Prime.int_from_prime_division([[3, 2], [5, 1]]) #=> 45 3**2 * 5 #=> 45