LoginSignup
0
0

More than 5 years have passed since last update.

CodeEval -Fizz Buzz-

Posted at

Fizz Buzz - CodeEval
Ruby 1.9.3 だった。もっとすっきりと書けそう。

File.open(ARGV[0]).each_line {|line|
    l = line.chomp.split(" ")
    x, y, n = l[0].to_i, l[1].to_i, l[2].to_i
    str = []
    (1..n).each{|t|
        if (t.modulo(x) == 0 ) && (t.modulo(y) == 0 )
            str << "FB"
        elsif (t.modulo(x) == 0 ) && (t.modulo(y) != 0 )
            str << "F"
        elsif (t.modulo(x) != 0 ) && (t.modulo(y) == 0 )
            str << "B"
        else
            str << "#{t}"
        end
    }
    puts str.join(" ")
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0