Created
September 29, 2014 16:10
-
-
Save Demannu/1ae5d7137ba957219ef6 to your computer and use it in GitHub Desktop.
[Exercism.io] Prime Factorization Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Prime Factor Storm | |
## Demannu 9/29/2014 | |
# 3 -> Pling | |
# 5 -> Plang | |
# 7 -> Plong | |
# If factors aren't 3,5,7 just display the number | |
require 'mathn' | |
class Raindrops | |
def self.convert(toFactor) | |
primeNumbers = [2, 3, 5, 7, 9] | |
primeFactors = [] | |
raindropString = "" | |
factors = toFactor.prime_division | |
factors.each do |factor| | |
case factor | |
when 3 | |
raindropString = raindropString.concat("Pling") | |
when 5 | |
raindropString = raindropString.concat("Plang") | |
when 7 | |
raindropString = raindropString.concat("Plong") | |
else | |
raindropString = toFactor | |
end | |
end | |
puts raindropString | |
end | |
end | |
# Issue is when you run this, no matter the number it returns nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment