Skip to content

Instantly share code, notes, and snippets.

@Epyon616
Last active July 24, 2018 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Epyon616/99bd3f92d011a06a5e0d to your computer and use it in GitHub Desktop.
Save Epyon616/99bd3f92d011a06a5e0d to your computer and use it in GitHub Desktop.
Decided to see if I could solve the age old fizz buzz test, it's probably not the most concise solution and its definitely not finished but it is at least readable
#!/usr/bin/env ruby
number_array = [*1..100]
def divisible_by(divisible, number)
number.modulo(divisible).zero?
end
number_array.each do |num|
puts "fizz buzz" if (divisible_by(3, num) && divisible_by(5, num))
puts "buzz" if divisible_by(3, num)
puts "fizz" if divisible_by(5, num)
puts num if (!divisible_by(3, num) && !divisible_by(5, num))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment