Given a positive integer, n, and a row vector, x, of positive integers, return a row vector, v, which is a sequence of length n of positive integers, beginning with [1 2...], in which integers that are the sums of any x(i) consecutive previous elements are omitted.
For example, if x = [2 3], meaning integers that are sums of any 2 or 3 consecutive previous elements should be omitted, the output would be v = [1 2 4 5 8 10...v(n)], because 3 is the sum of [1 2], 6 is the sum of [2 4], 7 is the sum of [1 2 4], 9 is the sum of [4 5], and so on, up to n elements of v.
If x = 0, integers that are the sums of any 2 or more consecutive previous elements should be omitted.
Solution Stats
Problem Comments
5 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers15
Suggested Problems
-
Return the largest number that is adjacent to a zero
5511 Solvers
-
Replace NaNs with the number that appears to its left in the row.
3059 Solvers
-
217 Solvers
-
Rotate input square matrix 90 degrees CCW without rot90
679 Solvers
-
65 Solvers
More from this Author45
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Please check test case 3, where number 7 is mistakenly skipped.
Also, number 12 in test case 4 ...
In test case 2, if x=0, should the sequence be 1:22 or completely empty?
@James: "If x = 0, integers that are the sums of any 2 or more consecutive previous elements should be omitted."
@Peng, thank you for the great catch. An illusive issue with my reference solution disrupted test cases 3 and 4. Now fixed.