Advertisement
WagnerMatosUK

talent_pipe

Mar 14th, 2024 (edited)
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.40 KB | None | 0 0
  1. def print_numbers
  2.   (1..100).each do |i|
  3.     if i % 3 == 0 && i % 5 == 0
  4.       puts 'APingBPong'
  5.     elsif i % 3 == 0
  6.       puts 'APing'
  7.     elsif i % 5 == 0
  8.       puts 'BPong'
  9.     else
  10.       puts i
  11.     end
  12.   end
  13. end
  14.  
  15. def print_numbers
  16.   (1..100).each do |i|
  17.     output = ''
  18.     output += 'APing' if i % 3 == 0
  19.     output += 'BPong' if i % 5 == 0
  20.     puts(output.empty? ? i : output)
  21.   end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement