Number of Straight-Chain Alk*nes of given length
MATL, 10 bytes
7K5vBiY^1)
Try it online!
Explanation
This uses the characterization found in OEIS
a(n) is the top left entry of the n-th power of the 3 X 3 matrix [1, 1, 1; 1, 0, 0; 1, 0, 1]
7 % Push 7
K % Push 4
5 % Push 5
v % Concatenate all numbers into a column vector: [7; 4; 5]
B % Convert to binary: gives 3×3 matrix [1, 1, 1; 1, 0, 0; 1, 0, 1]
i % Input n
Y^ % Matrix power
1) % Take the first element of the resulting matrix, i.e. its upper-left corner.
% Implicitly display
Oasis, 9 7 bytes
xcd-+3V
Try it online!
Explanation
This uses the recurrence relationship in OEIS:
a(n) = 2*a(n-1) + a(n-2) - a(n-3)
x Multiply a(n-1) by 2: gives 2*a(n-1)
c Push a(n-2)
d Push a(n-3)
- Subtract: gives a(n-2) - a(n-3)
+ Add: gives 2*a(n-1) + a(n-2) - a(n-3)
3 Push 3: initial value for a(n-1)
V Push 1, 1: initial values for a(n-2), a(n-3)
Oasis, 9 8 bytes
Saved a byte thanks to Adnan
xc+d-63T
Try it online!
Explanation
a(0) = 0
a(1) = 1
a(2) = 3
a(3) = 6
a(n) = xc+d-
x # calculate 2*a(n-1)
c # calculate a(n-2)
+ # add: 2*a(n-1) + a(n-2)
d # calculate a(n-3)
- # subtract: 2*a(n-1) + a(n-2) - a(n-3)