Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FizzBuzz code golf by ruby

gurrium
February 22, 2018

FizzBuzz code golf by ruby

FizzBuzz code golf for hiroshima.rb #062

gurrium

February 22, 2018
Tweet

More Decks by gurrium

Other Decks in Programming

Transcript

  1. (1..100).each do |i| puts "#{i} " if i % 3

    == 0 if i % 5 == 0 puts 'fizzbuzz' next else puts 'fizz' next end end if i % 5 == 0 puts 'buzz' next end end count 207
  2. (1..100).each do |i| print "#{i} " if i % 3

    == 0 puts i % 5 == 0 ? 'fizzbuzz' : 'fizz' next end puts i % 5 == 0 ? 'buzz' : nil end count 148
  3. (1..100).each do |i| print "#{i} " puts i % 3

    == 0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : nil end count 122
  4. (1..100).each { |i| print "#{i} " puts i % 3

    == 0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : nil } count 119
  5. (1..100).each { |i| print "#{i} ";puts i % 3 ==

    0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : nil } count 115
  6. (1..100).each { |i| print "#{i} “; puts i % 3

    == 0 ? i % 5 == 0 ? 'fizzbuzz' : 'fizz' : i % 5 == 0 ? 'buzz' : '' } count 114
  7. (1..100).each { |i| puts "#{i} #{'fizz' if i % 3

    == 0}#{'buzz' if i % 5 == 0}" } count 81
  8. 1.upto(100) { |i| puts "#{i} #{'fizz' if i % 3

    == 0}#{'buzz' if i % 5 == 0}" } count 79
  9. 1.upto(100) { |i| puts "#{i} #{'fizz' if i % 3

    < 1}#{'buzz' if i % 5 < 1}" } count 77