Module: PrimeProducts

Defined in:
lib/prime_products.rb,
lib/prime_products/cli.rb,
lib/prime_products/version.rb,
lib/prime_products/prime_numbers.rb,
lib/prime_products/multiplication_table.rb

Defined Under Namespace

Modules: CLI, MultiplicationTable, PrimeNumbers

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.generate_table(number_of_primes:) ⇒ String

Generates an ASCII “multiplications table” of the first ‘number_of_primes` prime numbers, starting from zero, suitable for presentation in a shell.

For example, if you pass in ‘5`, the result will be:

-------—-----—-+ | * | 1 | 2 | 3 | 4 | 5 | | 1 | 1 | 2 | 3 | 4 | 5 | | 2 | 2 | 4 | 6 | 8 | 10 | | 3 | 3 | 6 | 9 | 12 | 15 | | 4 | 4 | 8 | 12 | 16 | 20 | | 5 | 5 | 10 | 15 | 20 | 25 | -------—-----—-+

Parameters:

  • numbers (Array<Integer>, Immutable::SortedSet<Integer>)

    the number of prime numbers, starting from 0, you want to the multiplication table of

Returns:

  • (String)

    the generated table



26
27
28
29
# File 'lib/prime_products.rb', line 26

def self.generate_table(number_of_primes:)
  prime_numbers = PrimeNumbers.first(number_of_primes)
  MultiplicationTable.generate(prime_numbers)
end