simple-exercises/ruby-exercises/easy-3.rb
# Write a Xbonacci function that works similarly to the fibonacci sequence.
# The fibonacci sequence takes the previous two numbers in the sequence and adds
# them together to create the next number.
#
# First five fibonacci numbers = [1, 1, 2, 3, 5]
# The fourth fibonacci number (3) is the sum of the two numbers before it
# (1 and 2).
#
# In Xbonacci, the sum of the previous X numbers (instead of the previous 2 numbers)
# of the sequence becomes the next number in the sequence.
#
# The method will take two inputs: the starting sequence with X number of
# elements and an integer N, and return the first N elements in the given
# sequence.  Take a look at the test cases for examples.
#
# In the code, how_many_numbers_to_sum is the same as X (name your variables
# descriptively!).
#
# In the code, number_of_fibonacci_numbers_to_return is the same as N.
Write a Xbonacci function that works similarly to the fibonacci sequence.
The fibonacci sequence takes the previous two numbers in the sequence and adds
them together to create the next number.

First five fibonacci numbers = [1, 1, 2, 3, 5]
The fourth fibonacci number (3) is the sum of the two numbers before it
(1 and 2).

In Xbonacci, the sum of the previous X numbers (instead of the previous 2 numbers)
of the sequence becomes the next number in the sequence.

The method will take two inputs: the starting sequence with X number of
elements and an integer N, and return the first N elements in the given
sequence.  Take a look at the test cases for examples.

In the code, how_many_numbers_to_sum is the same as X (name your variables
descriptively!).

In the code, number_of_fibonacci_numbers_to_return is the same as N.
Write a Xbonacci function that works similarly to the fibonacci sequence . The fibonacci sequence takes the previous two numbers in the sequence and adds them together to create the next number . First five fibonacci numbers = [ 1 1 2 3 5 ] The fourth fibonacci number ( 3 ) is the sum of the two numbers before it ( 1 and 2 ) . In Xbonacci the sum of the previous X numbers ( instead of the previous 2 numbers ) of the sequence becomes the next number in the sequence . The method will take two inputs : the starting sequence with X number of elements and an integer N and return the first N elements in the given sequence . Take a look at the test cases for examples . In the code how_many_numbers_to_sum is the same as X ( name your variables descriptively! ) . In the code number_of_fibonacci_numbers_to_return is the same as N .
def xbonacci(starting_sequence, number_of_xbonacci_numbers_to_return)
  sequence = starting_sequence
  n = number_of_xbonacci_numbers_to_return
  x = starting_sequence.length
  i = n - x
  (0...i).each do |i|
    s = sequence[i...(x + i)].sum
    sequence << s
  end
  sequence
end
def xbonacci ( starting_sequence , number_of_xbonacci_numbers_to_return ) sequence = starting_sequence n = number_of_xbonacci_numbers_to_return x = starting_sequence . length i = n - x ( 0 ... i ) . each do | i | s = sequence [ i ... ( x + i ) ] . sum sequence << s end sequence end
Write a Xbonacci function that works similarly to the fibonacci sequence.
Write a Xbonacci function that works similarly to the fibonacci sequence .
# length of array to return # numbers of elements before to sum # numbers to add to array
starting_sequence
<not_specific>
number_of_xbonacci_numbers_to_return
<not_specific>