Skip to content

Instantly share code, notes, and snippets.

@Demannu
Created September 29, 2014 16:10
Show Gist options
  • Save Demannu/1ae5d7137ba957219ef6 to your computer and use it in GitHub Desktop.
Save Demannu/1ae5d7137ba957219ef6 to your computer and use it in GitHub Desktop.
[Exercism.io] Prime Factorization Code
## 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