simple-exercises/ruby-exercises/easy-8.rb
# Total Product Sequence
# ------------------------------------------------------------------------------
# The total product sequence starts with [1, 2, 3] as a "base case" (what you
# start with).  The next number in the sequence is the product of all the numbers
# before it.  Given a number n, find the nth number of the total product sequence.
#
# Assume n must be at least 1
Total Product Sequence
The total product sequence starts with [1, 2, 3] as a "base case" (what you
start with).  The next number in the sequence is the product of all the numbers
before it.  Given a number n, find the nth number of the total product sequence.

Assume n must be at least 1
Total Product Sequence The total product sequence starts with [ 1 2 3 ] as a " base case " ( what you start with ) . The next number in the sequence is the product of all the numbers before it . Given a number n find the nth number of the total product sequence . Assume n must be at least 1
def total_product_sequence(n)
  if n < 4
    return n
  end
  product = 6
  (4..n).each do |i|
    if i == n
      return product
    end
    product *= product
  end
end
def total_product_sequence ( n ) if n < 4 return n end product = 6 ( 4 .. n ) . each do | i | if i == n return product end product *= product end end
Total Product Sequence
The total product sequence starts with [1, 2, 3] as a "base case" (what you
start with).
Total Product Sequence The total product sequence starts with [ 1 2 3 ] as a " base case " ( what you start with ) .
n
<not_specific>