Fibonacci n-step number sequences: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: eliminate hard-coded value)
(→‎{{header|Ruby}}: Removed reference to Ruby 1.9; use sum method.)
Line 3,902: Line 3,902:


=={{header|Ruby}}==
=={{header|Ruby}}==
{{works with|Ruby|1.9}}
<lang ruby>def anynacci(start_sequence, count)
<lang ruby>def anynacci(start_sequence, count)
n = start_sequence.length # Get the n-step for the type of fibonacci sequence
n = start_sequence.length # Get the n-step for the type of fibonacci sequence
Line 3,908: Line 3,907:
(n+1..count).each do # Loop for the remaining results up to count
(n+1..count).each do # Loop for the remaining results up to count
result << result.last(n).reduce(:+) # Get the last n element from result and append its total to Array
result << result.last(n).sum # Get the last n element from result and append its total to Array
end
end