[Question]
  [
The [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_number) is a fairly well known thing around here. Heck, it even has its own tag. However, for all that, we sure like to stick to our roots of `1, 1, ...` (or is it `0, 1, ...`? We may never know...). In this challenge, the rules are the same, but instead of getting the `n`th item in the Fibonacci sequence, you will get the `n`th item in the Fibonacci-esque sequence starting with `x, y, ...`.
# Input
Three integers, in whatever order you want. `n` is the index (0 or 1 indexed) of term in the sequence for your output. `x` and `y` are the first two items in your current program run's Fibonacci sequence.
# Output
The `n`th term in the Fibonacci sequence starting with `x`, `y`.
# Test Cases
(0-indexed)
```
n   x     y     out
5   0     0     0
6   0     1     8
6   1     1     13
2   5     5     10
10  2     2     178
3   3     10    23
13  2308  4261  1325165
0   0     1     0
1   0     1     1
```
(1-indexed)
```
n   x     y     out
6   0     0     0
7   0     1     8
7   1     1     13
3   5     5     10
11  2     2     178
4   3     10    23
14  2308  4261  1325165
1   0     1     0
2   0     1     1
```
# Caveats
Assume `0 <= x <= y`.
Please note your input order (must be constant).
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
+¡ạ
```
Takes **x**, **y**, and **n** (0-indexed) as separate command-line arguments, in that order.
[Try it online!](https://tio.run/nexus/jelly#@699aOHDXQv///9v/N/Q4L8xAA "Jelly – TIO Nexus")
### How it works
```
+¡ạ  Main link. Left argument: x. Right argument: y. Third argument: n
  ạ  Yield abs(x - y) = y - x, the (-1)-th value of the Lucas sequence.
+¡   Add the quicklink's left and right argument (initially x and y-x), replacing
     the right argument with the left one and the left argument with the result.
     Do this n times and return the final value of the left argument.
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~14~~ 9 bytes
```
l~{_@+}*;
```
[Try it online!](https://tio.run/nexus/cjam#@59TVx3voF2rZf3/v5GCkYKhIQA "CJam – TIO Nexus")
Input format is "x y n".
I'm still a noob at this, so I'm 100% sure there are better ways to do this, but please instead of telling me "do this" try to only give me hints so that I can find the answer myself and get better. Thanks!
[Answer]
# [Python 2](https://docs.python.org/2/), 37 bytes
```
f=lambda x,y,n:n and f(y,x+y,n-1)or x
```
[Try it online!](https://tio.run/nexus/python2#@59mm5OYm5SSqFChU6mTZ5WnkJiXopCmUalToQ3k6xpq5hcpVPwvKMrMKwEKG@kY6RgaaP4HAA "Python 2 – TIO Nexus")
0-indexed, you may need to adjust the recursion limit for `n≥999`
[Answer]
# JavaScript (ES6), ~~27~~ 26 bytes
Nothing fancy here, just a standard JS Fibonacci function with the initial values of 0 & 1 removed.
```
n=>g=(x,y)=>n--?g(y,x+y):x
```
---
## Try it
```
f=
n=>g=(x,y)=>n--?g(y,x+y):x
o.value=f(i.value=13)(j.value=2308,k.value=4261)
oninput=_=>o.value=f(+i.value)(+j.value,+k.value)
```
```
*{font-family:sans-serif;}
input{margin:0 5px 0 0;width:50px;}
#o{width:75px;}
```
```
<label for=i>n: </label><input id=i type=number><label for=j>x: </label><input id=j type=number><label for=k>y: </label><input id=k type=number><label for=o>= </label><input id=o>
```
[Answer]
## Python 2, 40 bytes
0-indexed  
[Try it online](https://tio.run/nexus/python2#@5@nk6iTZJuZV1BaoqHJlVqRmqwOEkjSSdROslbXyuMqKMrMK1FI/P8/2tBAx0jHKBYA)
```
n,a,b=input()
exec'a,b=b,a+b;'*n
print a
```
[Answer]
# [Haskell](https://www.haskell.org/), 30 bytes
```
x#y=(f!!)where f=x:scanl(+)y f
```
[Try it online!](https://tio.run/nexus/haskell#Zc7NCsIwEATgu08xpR6ySCE/REXIwxRtsKBRWsHk6eMmXgzucb5h2Bz75ITvOnpfp2WCd/G0nsdwEztK8Pk@zgEOlwc2AIYB9UREj0QIJXwuc3hhCyE5lARbe/KPFGFf6diQ@iVlGrNslqC/1k5qNk2cVju0o6aM8i@moDb5Aw "Haskell – TIO Nexus") 0-indexed. Use as `(x#y)n`, e.g. `(0#1)5` for the fifth element of the original sequence.
The most likely shortest way to get the Fibonacci sequence in Haskell is [`f=0:scanl(+)1f`](https://codegolf.stackexchange.com/a/89/56433), which defines an infinite list `f=[0,1,1,2,3,5,8,...]` containing the sequence. Replacing `0` and `1` with arguments `x` and `y` yields the custom sequence. `(f!!)` is then a function returning the nth element of `f`.
[Answer]
## Mathematica, 36 bytes
```
LinearRecurrence[{1,1},{##2},{#+1}]&
```
input
> 
> [n,x,y]
> 
> 
> 
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 40 bytes
```
$n,$x,$y=$args;2..$n|%{$y=$x+($x=$y)};$y
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XyVPR6VCR6XSViWxKL3Y2khPTyWvRrUaJFChraFSYatSqVlrrVL5//9/0/@G/w0B "PowerShell – Try It Online")
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 38 bytes
```
{({}[()]<(({}<>)<>{}<(<>{}<>)>)>)}{}{}
```
[Try it online!](https://tio.run/nexus/brain-flak#@1@tUV0braEZa6MBZNjYadrYASkNMGmnCYK11UD4/78xl6EBlzEA "Brain-Flak – TIO Nexus")
```
{({}[()]<                      >)}     # For n .. 0
         (({}<>)<>            )        # Copy TOS to the other stack and add it to...
                  {}                   # The second value
                    <(<>{}<>)>         # Copy what was TOS back
                                  {}{} # Pop the counter and the n+1th result
```
[Answer]
# Ruby, 27 bytes
```
->a,b,n{n.times{b=a+a=b};a}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
;SḊµ¡I
```
[Try it online!](https://tio.run/nexus/jelly#@28d/HBH16GthxZ6/v//P9pIxyj2v6EhAA "Jelly – TIO Nexus")
**Explanation**
```
   µ¡  - repeat n times (computes the n+1th and n+2th element):
 S     -  take the sum of the elements of the previous iteration (starting at (x,y))
;      -  append to the end of the previous iteration
  Ḋ    -  remove the first element
     I - Take the difference of the n+1th and n+2th to get the n-th.
```
[Answer]
# [TAESGL](https://github.com/tomdevs/taesgl), 4 bytes
```
ēB)Ė
```
1-indexed
[**Interpreter**](https://tomdevs.github.io/TAESGL/v/1.3.1/index.html?code=XHUwMTEzQilcdTAxMTY=&input=NyxbMSwxXQ==)
**Explanation**
Input taken as `n,[x,y]`
```
 ēB)Ė
AēB)     get implicit input "A" Fibonacci numbers where "B" is [x,y]
    Ė    pop the last item in the array
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 77 bytes
```
f(N,Y,Z):-M is N-1,f(M,X,Y),Z is X+Y.
l(N,A,B,X):-asserta(f(0,A,B)),f(N,X,_).
```
[Try it online!](https://tio.run/nexus/prolog-swi#JYy7DsMgDEX3fkVGrN4gDE1UdUufUzJDlipDkCplKv1/aojOcnx97RzVhICZLu3YfFIztYyoRngEwlwSfwz6sElrwBVeektK6/e3qKhMyYhQfni8See8qQ5GGAhy1IuxVHZn4VbdohPu1dnACo86ODhI8Nw3DtaZM062Z7xI/wE "Prolog (SWI) – TIO Nexus")
Started off golfing [Leaky Nun's answer](https://codegolf.stackexchange.com/a/121135/69074) and arrived at something completely different.
This one has a rule for `(Nᵗʰ, (N+1)ᵗʰ)` in terms of `((N-1)ᵗʰ, Nᵗʰ)` and uses [database management](http://www.swi-prolog.org/pldoc/man?section=db) to assert 0ᵗʰ and 1ˢᵗ elements at runtime.
`f(N,X,Y)` means `Nᵗʰ` element is `X` and `(N+1)ᵗʰ` element is `Y`.
[Answer]
# R, 39 bytes
```
f=function(x,y,n)'if'(n,f(y,x+y,n-1),x)
```
A simple recursive function. Funnily enough this is shorter than anything I can come up with for the regular Fibonacci sequence (without built-ins), because this doesn't have to assign `1` to both `x` and `y` =P
Calculates `n+1` numbers of the sequence, including the initial values. Each recursion is calculates with `n-1` and stopped when `n==0`. The lowest of the two numbers is then returned, giving back the `n`-th value.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 24 bytes
```
@(n,x)(x*[0,1;1,1]^n)(1)
```
Input format: `n,[x,y]`.
[Try it online!](https://tio.run/nexus/octave#NcvLCoAgFIThfU/R8hiDOMeUIILeQ2zpsrVvb3bbfTPwl3EbrbVtlxPVSJ2SA1eC@TiN0LQiAf1z2QxF4k3@5EdFCggP6ZAU@tgjefAN2Yd6t2DW2KN2AQ "Octave – TIO Nexus")
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 85 bytes
```
l(0,X,Y,X).
l(1,X,Y,Y).
l(N,X,Y,C):-M is N-1,P is N-2,l(M,X,Y,A),l(P,X,Y,B),C is A+B.
```
[Try it online!](https://tio.run/##JcwxDoMwDAXQvadgjNWfKA6CoRuEdgMxwgkqpEggGDg@OEZ/efa3vO1rWv/2OJfrSsZjwoyJ3CsZVs/qQR3pY/tiOYrBMsYHAcn02jYkHJUtIea6ebcuv63gJXIgr2oR5ws1S6I6oJJ0avYIkq8OJUrI4kfuBg "Prolog (SWI) – Try It Online")
0-indexed.
[Answer]
# x86 machine code, 7 bytes
`EDX = x = fib[1]`, `EAX = y = fib[2]`, `RCX = n` (1-indexed)  
returns in EAX. Works in all 3 modes (16, 32, and 64).  
```
0000000000401070 <cfib>:
  401070:       eb                      .byte 0xeb      # jmp rel8 consuming the 01 add opcode as a rel8
0000000000401071 <cfib.loop>:
  401071:       01 d0                   add    eax,edx
# loop entry point on first iteration, jumping over the ModRM byte of the ADD
  401073:       92                      xchg   edx,eax
  401074:       e2 fb                   loop   401071 <cfib.loop>
  401076:       c3                      ret 
```
This "jumps" into the loop with machine code that decodes 2 different ways: with a `jmp +1` when falling into the loop from the top of the function, or with that `01` byte being an ADD opcode when the `loop` instruction jumps backwards. Equivalent to `jmp .entry` but with only 1 byte outside the loop instead of 2.
(Credit to [@Ira Baxter](https://stackoverflow.com/questions/10765317/can-assembled-asm-code-result-in-more-than-a-single-possible-way-except-for-off/10766612#10766612) for pointing out the general idea of falling into a loop with 1 byte outside that consumes some loop bytes to do something different on the first iteration, e.g. the opcode for `cmp al, imm8` as a 1-byte encoding for a jump forward by 1. I got lucky that `01 add` could be consumed by jmp rel8 to skip a total of 2 bytes without needing a `66` prefix for `cmp ax, imm16` or being in 16-bit mode. 01 or 03 add didn't work well as a modrm for anything like `add r/m32, imm8`; we need to avoid a memory operand. Note that this trick is *not* good for performance on some modern CPUs, e.g. AMD that caches instruction boundaries in L1i tags, and probably not newer Intel/AMD with uop caches.)
Stripping labels lets objdump decode as the CPU would on the first pass:
```
cfib:
  401070:       eb 01                   jmp    0x401073   # jmp rel8 = +1
  401072:       d0                      .byte 0xd0        # jumped over
  401073:       92                      xchg   edx,eax
  401074:       e2 fb                   loop   0x401071
  401076:       c3                      ret    
```
It's easy to see that the EDX input will be the EAX return value for ECX=1 (exit right away, `loop` is never taken so `add` never runs).
Use `strace ./custom-fib 14 2308 4261` to see the full integer value passed to the `exit()` system call before truncation to an 8-bit exit status.
In 32-bit mode, the same machine code is callable with GCC regparm(3) calling convention as `__attribute__((regparm(3))) unsigned custom_fib(unsigned y /*eax*/, unsigned x /*edx*/, unsigned n /*ecx*/);`, returning in EAX as usual.
---
## Without the 2-way decode hack: x86 machine code, 8 bytes
0-indexed `n` in RCX, `x` (`fib[0]`) in EAX, y (`fib[1]`) in EDX - note opposite arg order
```
0000000000401070 <cfib>:
  401070:       e3 05                   jrcxz  401077 <cfib.done>
0000000000401072 <cfib.loop>:
  401072:       0f c1 c2                xadd   edx,eax
  401075:       e2 fb                   loop   401072 <cfib.loop>
0000000000401077 <cfib.done>:
  401077:       c3                      ret    
```
This way shows off x86's [`xadd`](https://www.felixcloutier.com/x86/xadd) instruction, normally only used with a memory destination and a `lock` prefix to implement `fetch_add`.
The reg,reg form of `xadd` decodes to only 3 uops on Intel Skylake, [same as `xchg reg,reg`](https://stackoverflow.com/questions/45766444/why-is-xchg-reg-reg-a-3-micro-op-instruction-on-modern-intel-architectures) (<https://uops.info/>). (The `loop` instruction is slow on Intel so this is hardly optimized for speed. If you want a speed-efficient asm implementation, unroll by 2 to remove the xchg as shown [in my SO answer](https://stackoverflow.com/questions/32659715/assembly-language-x86-how-to-create-a-loop-to-calculate-fibonacci-sequence/32661389#32661389) using clever loop setup to avoid excess branching for odd vs. even `n` for standard 0,1 Fibonacci.)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 5 bytes
```
⁽+dḞi
```
Takes input as `[x, y]` then `n`.
[Try it online!](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwi4oG9K2ThuJ5pIiwiIiwiWzAsIDBdLCA1XG5bMCwgMV0sIDZcblsxLCAxXSwgNlxuWzUsIDVdLCAyXG5bMiwgMl0sIDEwXG5bMywgMTBdLCAzXG5bMjMwOCwgNDI2MV0sIDEzXG5bMCwgMV0sIDBcblswLCAxXSwgMSJd)
Explanation:
```
   Ḟ   # Create an infinite list from the initial vector [x, y] from:
  d    # a dyadic,
⁽      # single element lambda
 +     # which adds its two arguments.
    i  # Index into that list with the second input (n).
```
[Answer]
# [Python 2](https://docs.python.org/2/), 112 bytes
1-indexed.
```
import itertools
def f(x,y):
 while 1:yield x;x,y=y,x+y
def g(x,y,n):return next(itertools.islice(f(x,y),n-1,n))
```
[Try it online!](https://tio.run/nexus/python2#PcxBCsIwEIXhfU8xywRHMatCxNPYqQ6kkzKd0uT0MSq4fXzvb7ysWQ3YSC3ntA0TzTC7gtXHAY4XJ4IQK1OaoNz6fK9YTvXLnh@G4qOS7SogVMz9SxfeEj/I/WIo59Cpb6uyWL9eMeDo2xs "Python 2 – TIO Nexus")
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 36 bytes
```
?sdsbsa[lddlb+sdsbla1-dsa1<c]dscxldp
```
[Try it online!](https://tio.run/nexus/dc#@29fnFKcVJwYnZOSkpOkDeLkJBrqphQnGtokx6YUJ1fkpBT8/29orGBkbGChYGJkZggA "dc – TIO Nexus")
`0`-indexed. Input must be in the format `n x y`. 
[Answer]
# PHP>=7.1, 55 Bytes
```
for([,$n,$x,$y]=$argv;$n--;$x=$y,$y=$t)$t=$x+$y;echo$x;
```
[Online Version](http://sandbox.onlinephpfunctions.com/code/3d0a076a75c2163d9f443a59f165aaf955d2a2af)
# PHP>=7.1, 73 Bytes
```
for([,$n,$x,$y]=$argv,$r=[$x,$y];$i<$n;)$r[]=$r[+$i]+$r[++$i];echo$r[$n];
```
[Online Version](http://sandbox.onlinephpfunctions.com/code/c1acd204195b92546d7b998c39234efb2e567aef)
[Answer]
# Common Lisp, 49 Bytes, 0-indexed
```
(defun fib(n x y)(if(= 0 n)x(fib(1- n)y(+ x y))))
```
I'm a Lisp noob so any tips would be appreciated ;)
### Explanation:
```
(defun fib(n x y)                                  | Define a function taking 3 arguments
                 (if(= 0 n)x                       | If n = 0, return x
                            (fib(1- n)y(+ x y))))  | Otherwise, call fib with n-1, y, and x+y
```
[Answer]
# br\*\*nfuck, ~~39~~ 29 bytes
Thanks to @JoKing for -10!
```
,<,<,[>[>+>+<<-]<[>+<-]>-]>>.
```
TIO won't work particularly well for this (or for any BF solution to a problem involving numbers). I strongly suggest @Timwi's [EsotericIDE](https://github.com/Timwi/EsotericIDE) (or implementing BF yourself).
Takes `x`, then `y`, then `n`. 0-indexed. Assumes an unbounded or wrapping tape.
### Explanation
```
,<,<,            Take inputs. Tape: [n, y, x]
[                While n:
  > [->+>+<<]      Add y to x, copying it to the next cell along as well. Tape: [n, 0, x+y, y]
  < [>+<-]         Move n over. Tape: [0, n, x+y, y]
  >-               Decrement n.
] >>.            End loop. Print cell 2 to the right (x for n == 0).
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 29 bytes
```
f(n,x,y){n=n?f(n-1,y,x+y):x;}
```
[Try it online!](https://tio.run/##bdBNbsIwEAXgNTnFiIoqphMUJxWiTQMHqVgE5wdL7lA5prKFuHqNrbJAUXcz732bGZENQvgnSUKd2@5jNK08rY7b5DFR8hAi36eEFh27UE27sGQcHdoXx95tdfWSDHw1ktI4NHoQCOLYaFgu4/bD4JLM/gLoqK2SWXQENYxGm5NSaVSffI/wHHoEnrM7slNU/IPcFJUT9K0D69P5op0jxFPAIjgWK92ZsybIq@TqPS99UeYb/1qs@a/oVTOMPgtPqMVbfgM "C (gcc) – Try It Online")
This implementation is 0-based.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
:"wy+]x
```
Output is 0-based.
Try it at [MATL Online!](https://matl.io/?code=%3A%22wy%2B%5Dx&inputs=10%0A2%0A2&version=19.11.0)
### Explanation
Let the inputs be denoted `n` (index), `a`, `b` (initial terms).
```
:"     % Implicitly input n. Do this n times
       %   At this point in each iteration, the stack contains the two most
       %   recently computed terms of the sequence, say s, t. In the first
       %   iteration the stack is empty, but a, b will be implicitly input
       %   by the next statement
  w    %   Swap. The stack contains t, s
  y    %   Duplicate from below. The stack contains t, s, t
  +    %   Add. The stack contains t, s+t. These are now the new two most
       %   recently comnputed terms
]      % End
x      % Delete (we have computed one term too many). Implicitly display
```
[Answer]
# [Braingolf](https://github.com/gunnerwolf/braingolf), 15 bytes
```
VR<2-M[R!+v]R_;
```
`_;` is no longer needed on the latest version of Braingolf, however that's as of ~5 minutes ago. This could be 13 bytes by removing that.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
`©GDŠ+}®@
```
[Try it online!](https://tio.run/nexus/05ab1e#@59waKW7y9EF2rWH1jn8/x9trGNooGMSCwA "05AB1E – TIO Nexus")
**Explanation**
```
`           # split inputs as separate to stack
 ©          # store n in register
  G         # n-1 times do
   D        # duplicate top of stack
    Š       # move down 2 places on stack
     +      # add top 2 values of stack
      }     # end loop
       ®@   # get the value nth value from the bottom of stack
```
[Answer]
# [Lua](https://www.lua.org), 44 bytes
0-Indexed
```
n,x,y=...for i=1,n do
x,y=y,x+y
end
print(x)
```
[Try it online!](https://tio.run/nexus/lua#@5@nU6FTaaunp5eWX6SQaWuok6eQks8FEqvUqdCu5ErNS@EqKMrMK9Go0Pz//7@h8X8jYwOL/yZGZoYA "Lua – TIO Nexus")
[Answer]
# [Klein](https://github.com/Wheatwizard/Klein), 18 + 3 bytes
This uses the `000` topology
```
:?\(:(+)$)1-+
((/@
```
Pass input in the form `x y n`.
[Answer]
# Axiom, ~~88~~ 57 bytes
```
f(k,x,y)==(repeat(k<=0=>break;c:=y;y:=x+y;x:=c;k:=k-1);x)
```
this would pass the test proposed (0 indexed)
```
(14) -> f(5,0,0)
   (14)  0
                                                 Type: NonNegativeInteger
(15) -> f(6,0,1)
   (15)  8
                                                    Type: PositiveInteger
(16) -> f(2,5,5)
   (16)  10
                                                    Type: PositiveInteger
(17) -> f(10,2,2)
   (17)  178
                                                    Type: PositiveInteger
(18) -> f(3,3,10)
   (18)  23
                                                    Type: PositiveInteger
(19) -> f(13,2308,4261)
   (19)  1325165
                                                    Type: PositiveInteger
```
]