Advertisement
Dijit

fizzbuzz.rb

Feb 22nd, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.57 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # I suck but I heard about this thing called "FizzBuzz" which is apparently an interview question, so I consider it to be enough to get me a job in ruby (lol)
  3. # Expected output: if a number is divisable by 3, then print "Fizz", same for the number 5 except the word is "Buzz"
  4. # FizzBuzz should be printed if the number is divisable by both.
  5.  
  6.  
  7. for i in (1..100)
  8.     if #{i}/3 == 0 && #{i}/5 == 0
  9.         puts "FizzBuzz"
  10.     elsif #{i}/3  == 0
  11.         puts "Fizz"
  12.     elsif #{i}/5 == 0
  13.         puts "Buzz"
  14.     else
  15.         puts "#{i}"
  16.     end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement