Prime Factorization

Submitted By:
david

Difficulty:
Medium

Tags:
math, primes, factorization

Instructions:
Any number can be written as a product of prime numbers. For example, 42 would be "2 * 3 * 7" while 44 would be "2 * 2 * 11". Write a number to return an array of prime factors in ascending order for a given number.

Code:
___

assert_equal prime_factorization(42), [2, 3, 7]
assert_equal prime_factorization(44), [2, 2, 11]
assert_equal prime_factorization(75), [3, 5, 5]
assert_equal prime_factorization(123456), [2, 2, 2, 2, 2, 2, 3, 643]

Your Solution

Ruby 1.9.3

Back to Problems