Solution to 126


Here is my solution. I made the assumption that the interviewer has a
terminal handy and I have 5-10 minutes to crank this out. If I was just
writing it down on paper, I made a note of a couple things that I got
before I had a chance to see the output:

for i in 1…101 # was 100 before checking this
out = ‘’
out = out + ‘Fizz’ if (i % 3) == 0
out = out + ‘Buzz’ if (i % 5) == 0
out = i.to_s if (out.size) == 0

print out + “\n” # Original did not have a newline



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs