1
\$\begingroup\$

Introduction

The Fibonacci sequence is a mathematical sequence in which each term is the sum of the \$2\$ terms before it; the first two terms are \$0\$ and \$1\$. The first few terms are \$0, 1, 1, 2, 3, 5, 8, 13\$. However, it is possible to make variations of this sequence, where each term is the sum of the, say \$3\$ terms before it, of the sum of the previous \$4\$. That is what you must do in this challenge.

Challenge

Given two numbers, an index in the sequence \$n\$ and a number of terms \$x\$ to sum, generate the first \$n\$th terms in the messed up Fibonacci sequence. You can assume that the first \$x\$ terms are just the first \$x\$ whole numbers (\$0\$ and up).

  • Your program must take two numbers as input. You can assume that \$n\$, the first number, will always be greater than the second, \$x\$, and that \$x\$ will always be greater than or equal to 2. They will always be valid integers. If it is easier or if it saves bytes to read from stdin, command line arguments, or a variable, you may do one of those options.
  • Your program must output the first \$n\$ terms in the Fibonacci sequence in which each term is the sum of the last \$x\$ numbers. Again, if it saves bytes, your program may output through stdout, a variable, exit code, or return value.

Example I/O

  • n: 8, x: 2
    Output: {0, 1, 1, 2, 3, 5, 8, 13}
  • n: 7, x: 4
    Output: {0, 1, 2, 3, 6, 12, 32}
  • n: 4, x: 3
    Output: {0, 1, 2, 3}

Rules

This is , so shortest answer in bytes wins!

`

\$\endgroup\$
2
  • \$\begingroup\$ You can assume that the first x terms are just the first x whole numbers (0 and up). But in the last test case, the first three terms are not the first three whole numbers \$\endgroup\$ – Gymhgy Nov 9 '19 at 3:34
  • 2
    \$\begingroup\$ This looks really similar to Print the N-bonacci sequence, with just a different base case. I think dupe? \$\endgroup\$ – xnor Nov 9 '19 at 3:36