6 kyu

Prime factorization

161 of 1,441wengzilla

Description:

The prime factorization of a positive integer is a list of the integer's prime factors, together with their multiplicities; the process of determining these factors is called integer factorization. The fundamental theorem of arithmetic says that every positive integer has a single unique prime factorization.

The prime factorization of 24, for instance, is (2^3) * (3^1).

Without using the prime library, write a class called PrimeFactorizer whose constructor accepts exactly 1 integer and has an instance method factor returning a hash where the keys are prime numbers and the values are the multiplicities.

PrimeFactorizer.new(24).factor #should return { 2 => 3, 3 => 1 }
PrimeFactorizer(24).factor #should return { 2: 3, 3: 1 }
new PrimeFactorizer(24).factor //should return { '2': 3, '3': 1 }
new PrimeFactorizer().factor(24) //should return { 2 => 3, 3 => 1 }
prime_factors(24); // => @{@"2": @3, @"3": @1}
Algorithms

More By Author:

Check out these other kata created by wengzilla

Stats:

CreatedApr 13, 2014
PublishedApr 13, 2014
Warriors Trained4479
Total Skips1130
Total Code Submissions11110
Total Times Completed1441
Ruby Completions161
Python Completions659
JavaScript Completions360
Java Completions321
Objective-C Completions13
Total Stars132
% of votes with a positive feedback rating90% of 225
Total "Very Satisfied" Votes187
Total "Somewhat Satisfied" Votes29
Total "Not Satisfied" Votes9
Ad
Contributors
  • wengzilla Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • blr_Oliver Avatar
  • donaldsebleung Avatar
  • Firefly2002 Avatar
  • Voile Avatar
  • cliffstamp Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad