fizzbuzzer - 1, 2, Fizz, 4, Buzz, Fizz,... - a collection of fizz buzz algorithms

Hello,

   I’ve put together a new fizzbuzzer command line tool and library (gem) [1].

   1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, …

    The fizzbuzzer library includes a collection of algorithms for
playing the word game for children that teaches division (one of the
four basic arithmetic operations in mathematics) or helps you find the
world’s best coders in programming job interviews.

    Are you (re)using the fizzbuzzer library? :wink: Don’t reinvent the
wheel or the feedbuzzer!

   Cheers.

[1] https://github.com/rubylibs/fizzbuzzer

PS: Here's the fizz buzz gold standard algorithm:

def fizzbuzz
  [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14,
  "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26,
  "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38,
  "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz",
  "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62,
  "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74,
  "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86,
  "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98,
  "Fizz", "Buzz"]
end

puts fizzbuzz.join( ", ")

This is great, but sometimes it's necessary to bring in a truly
bulletproof and cutting-edge tool for the most demanding FizzBuzz
contexts. For those times, there's
https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition\.

- Nathaniel Barnes

···

On Mon, Jan 22, 2018 at 6:02 AM, Gerald Bauer <gerald.bauer@gmail.com> wrote:

Hello,

   I’ve put together a new fizzbuzzer command line tool and library (gem) [1].

   1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, …

    The fizzbuzzer library includes a collection of algorithms for
playing the word game for children that teaches division (one of the
four basic arithmetic operations in mathematics) or helps you find the
world’s best coders in programming job interviews.

    Are you (re)using the fizzbuzzer library? :wink: Don’t reinvent the
wheel or the feedbuzzer!

   Cheers.

[1] https://github.com/rubylibs/fizzbuzzer

PS: Here's the fizz buzz gold standard algorithm:

def fizzbuzz
  [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14,
  "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26,
  "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38,
  "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz",
  "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62,
  "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74,
  "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86,
  "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98,
  "Fizz", "Buzz"]
end

puts fizzbuzz.join( ", ")

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hello,

   That's a classic. Inspired by FizzBuzz in too much detail by Tom
Dalling [1] I've added:

   FIZZBUZZ_DEFAULT_RANGE = 1..100

FIZZBUZZ_DEFAULT_MATCHERS = [["Fizz", ->(n){ n % 3 == 0 }],
                              ['Buzz', ->(n){ n % 5 == 0 }]]

def fizzbuzz_engine(range=FIZZBUZZ_DEFAULT_RANGE,
matchers=FIZZBUZZ_DEFAULT_MATCHERS)
  range.map do |n|
    result = ""
    matchers.each do |(text, predicate)|
      result << text if predicate.call(n)
    end
    result == "" ? n : result
  end
end

def fizzbuzz
  fizzbuzz_engine
end

puts fizzbuzz.join( ", ")

   Not yet at the Java Enterprise level though - needs at least a
denpendency injection container, enterprise logging, and some more
goodies :-).

   Cheers.

PS: My favorite version - Lazy Enumarator to Infinity!

require "bigdecimal"

module FizzBuzz
  def self.enumerator
    Enumerator::Lazy.new(1..BigDecimal::INFINITY) do |yielder, n|
       yielder << if n % 3 == 0 && n % 5 == 0 then "FizzBuzz"
                  elsif n % 3 == 0 then "Fizz"
                  elsif n % 5 == 0 then "Buzz"
                  else n
                  end
    end
  end
end

def fizzbuzz
  FizzBuzz.enumerator.take( 100 ).force # or first( 100 ) is
always eager by default
end

puts fizzbuzz.join( ", ")

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