kholdrex / fizzbuzz

Fizz buzz is a group word game for children to teach them about division.

Home Page:https://fizzbuzz-example.herokuapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

Fizz buzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word “fizz”, and any number divisible by five with the word “buzz”.

Tools:

  • Ruby 2.3.1

  • Rails 4.2.7.1

  • Materialize

  • Turbolinks

  • Heroku

Main class:

require 'singleton'

class FizzBuzz
  AMOUNT_OF_ITERATIONS = 100
  MAX_ITERATIONS = 5000
  DEFAULT = { '15' => 'FizzBuzz', '3' => 'Fizz', '5' => 'Buzz' } # 3 * 5 = 15 - dividable by 3 and 5

  include Singleton

  def call(n = AMOUNT_OF_ITERATIONS)
    return if !n.is_a?(Integer) || n.zero?

    amount_of_iterations = n > MAX_ITERATIONS ? MAX_ITERATIONS : n
    process([], 1, amount_of_iterations)
  end

  private

  def process(current_result, current_iter, max_iter)
    return current_result if current_iter > max_iter

    new_value = value_or_number(current_iter)
    process(current_result.push(new_value), current_iter + 1, max_iter)
  end

  def dividable?(x, y)
    (x % y) == 0
  end

  def value_or_number(iter)
    DEFAULT.each do |k, v|
      return v if dividable?(iter, k.to_i)
    end
    iter
  end
end

About

Fizz buzz is a group word game for children to teach them about division.

https://fizzbuzz-example.herokuapp.com


Languages

Language:Ruby 73.0%Language:HTML 26.5%Language:JavaScript 0.4%Language:CSS 0.1%