[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: fizzbuzzer - 1, 2, Fizz, 4, Buzz, Fizz, ... - a collection of fizz buzz algorithms
From: Gerald Bauer <gerald.bauer () gmail ! com>
Date: 2018-01-25 17:06:46
Message-ID: CAAxEZd9e1nKzjmUMid5cAOi0WdGV1h0qO5tifHQg6OtC-gVMuA () mail ! gmail ! com
[Download RAW message or body]
Hello,
I added some code golfing one-liner samples (less is more) to the FizzBuzzer:
62 Bytes
def fizzbuzz
(1..100).map{|n|n%15<1?"FizzBuzz":n%5<1?"Buzz":n%3<1?"Fizz":n}
end
58 Bytes
def fizzbuzz
(1..100).map{|n|"#{[:Fizz][n%3]}#{[:Buzz][n%5]}"[/.+/]||n}
end
And the winner is...
54 Bytes
def fizzbuzz
(1..100).map{|n|n%3<1&&x="Fizz";n%5<1?"#{x}Buzz":x||n}
end
# or
def fizzbuzz
(1..100).map{|n|["%sBuzz"%x=["Fizz"][n%3]][n%5]||x||n}
end
Cheers.
[1] https://github.com/rubylibs/fizzbuzzer
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic