Wednesday 25 January 2017

fizzbuzz in ruby

#!/usr/bin/env ruby

(1..100).each do |num|
  three = (num % 3 == 0)
  five = (num % 5 == 0)
  print 'fizz' if three
  print 'buzz' if five
  print num if (!three and !five)
  puts
end

1 comment:

  1. Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
    AWS Training in Chennai

    ReplyDelete

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...