Created
April 13, 2011 03:05
-
-
Save ballpointcarrot/916887 to your computer and use it in GitHub Desktop.
A FizzBuzz-styled programming question for a job application.
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 fizzbuzz | |
fifteens = temp = 0 | |
0.upto(1000).collect do |x| | |
fifteens += x if x % 15 == 0 | |
temp += x if ((x % 3 == 0) ^ (x % 5 == 0)) | |
end | |
puts "Single fifteens: #{temp + fifteens}" | |
puts "Double fifteens: #{temp + (fifteens * 2)}" | |
end | |
fizzbuzz | |
"Single fifteens: 234168" | |
"Double fifteens: 267333" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment