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