Skip to content

Instantly share code, notes, and snippets.

@ballpointcarrot
Created April 13, 2011 03:05
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 ballpointcarrot/916887 to your computer and use it in GitHub Desktop.
Save ballpointcarrot/916887 to your computer and use it in GitHub Desktop.
A FizzBuzz-styled programming question for a job application.
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