Problem 57730. Easy Sequences 97: One-line Code Challenge - Sequence with Constant Difference
While answering Problem #57725, I noticed a pattern that immediately led me to a solution, namely: the 4-th difference of the sequence is constant. In that problem's case the constant is 6:
diff(A,4) == [6 6 6 6 ...]
where A is the sequence.
Given an integer n and a vector V that enumerates the first k elements of A, write a function that outputs the n-th element of A, such that the
-th difference is a constant:
diff(A,k-1) == [c c c c ...]
-------------
NOTE: The following restrictions apply:
- The function should only have one (1) line of code, excluding the function start line.
- Semicolons (;) are considered end-of-line characters.
- To encourage vectorization, for and while loops are not allowed
- Regular expressions, string manipulation and curve fitting are not allowed.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers1
Suggested Problems
-
How to find the position of an element in a vector without using the find function
2710 Solvers
-
578 Solvers
-
Numbers spiral diagonals (Part 2)
142 Solvers
-
Divisible by n, prime divisors (including powers)
89 Solvers
-
Compute the sum of reciprocals of quadratics
10 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!