From 48449f528e1fc1ac0e58bc723b94c9e1dee157e1 Mon Sep 17 00:00:00 2001 From: HardikPurohit Date: Fri, 27 Jan 2017 11:49:23 +0530 Subject: [PATCH] Prime Factors --- prime_factors.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 prime_factors.rb diff --git a/prime_factors.rb b/prime_factors.rb new file mode 100644 index 0000000..feb16a8 --- /dev/null +++ b/prime_factors.rb @@ -0,0 +1,10 @@ +require 'prime' +class PrimeFactors + def self.for(num) + return [] if num == 1 + result = [] + num = num.prime_division + num.each { |i| i[1].times { result << i[0] } } + result + end +end