fork(1) download
  1. #!/usr/bin/env ruby
  2.  
  3. =begin
  4.  
  5. = Fizz Buzz
  6.  
  7. CodeEval [http://w...content-available-to-author-only...l.com/open_challenges/1/]
  8.  
  9. 1. Input example
  10.  
  11.   3 5 10
  12.   2 7 15
  13.  
  14. 2. Output example
  15.  
  16.   1 2 F 4 B F 7 8 F B
  17.   1 F 3 F 5 F B F 9 F 11 F 13 FB 15
  18.  
  19. 3. Run this program
  20.  
  21.   $ ruby fizzbuzz.rb input.txt
  22.   1 2 F 4 B F 7 8 F B
  23.   1 F 3 F 5 F B F 9 F 11 F 13 FB 15
  24.  
  25. =end
  26.  
  27. def fizzbuzz a, b, n
  28. (1..n).map do |x|
  29. case
  30. when x % (a * b) == 0 then 'FB'
  31. when x % a == 0 then 'F'
  32. when x % b == 0 then 'B'
  33. else x
  34. end
  35. end
  36. end
  37.  
  38. if __FILE__ == $0
  39. File::open(ARGV.first) do |f|
  40. f.each do |l|
  41. puts fizzbuzz(*l.split.map { |x| x.to_i }).join ' '
  42. end
  43. end
  44. end
Runtime error #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
Standard output is empty