Given a Natural number N, return the sequence - [1 1 2 1 2 3 1 2 3 4 ... 1 2 3 ... N-3 N-2 N-1 N] i.e. the horizontal concatenation of (1:k) for k=1:N
%Example 1
N=3;
Out=[1, 1 2, 1 2 3];
%Example 2
N=7;
Out=[1, 1 2, 1 2 3, 1 2 3 4, 1 2 3 4 5, 1 2 3 4 5 6, 1 2 3 4 5 6 7];
As the question deals with vectors, the solutions must be vectorized as well. Check the test suite for banned functions.
There will be a second part to this question.
Solution Stats
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers12
Suggested Problems
-
Replace NaNs with the number that appears to its left in the row.
3064 Solvers
-
Check to see if a Sudoku Puzzle is Solved
338 Solvers
-
Least common multiple of many numbers
255 Solvers
-
Remove the two elements next to NaN value
703 Solvers
-
271 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Enjoyed this problem (and liked it). An interesting problem set idea that I haven't seen, but I feel like you could put together: programming problems that must be solved through vectorized solutions to earn a badge. I'm not a vectorizing purist to be clear (and wouldn't encourage that at the potential expense of things like readability), but such problems do force you to think about what tools MATLAB has, and encouraging awareness of those tools is worthwhile.