Last active
February 11, 2019 13:54
-
-
Save Castone22/c3eb09a2be2578e7b3266a396eb2f9f0 to your computer and use it in GitHub Desktop.
hashbuzz
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
# Faster solution using map, bottleneck'd by ruby's puts method. | |
def buzz_hash(arg_hash) | |
hash_thing = {} | |
arg_hash.each do |key, value| | |
hash_thing[key] = value | |
end | |
@buzz_hash = hash_thing | |
end | |
def fizz!(number, min: 0) | |
results = (min..number).map do |index| | |
fizzable = @buzz_hash.select{|key, value| index % value == 0} | |
result = index if(index == 0 || fizzable.keys.empty?) | |
result ||= fizzable.keys.join('') | |
result | |
end | |
puts results.join("\n") | |
end | |
buzz_hash(fizz: 3, buzz: 5, bazz: 7, bozz: 13) | |
fizz!(100000) |
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
def buzz_hash(arg_hash) | |
hash_thing = {} | |
arg_hash.each do |key, value| | |
hash_thing[key] = value | |
end | |
@buzz_hash = hash_thing | |
end | |
def fizz!(number, min: 0) | |
(min..number).each do |index| | |
fizz = '' | |
fizzable = @buzz_hash.select{|key, value| index % value == 0} | |
fizzable.keys.each{|fizz_word| fizz << fizz_word.to_s} | |
fizz = index if fizz == '' || index == 0 | |
puts fizz | |
end | |
end | |
buzz_hash(fizz: 2, buzz: 5, bazz: 7) | |
fizz!(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment