Problem 1035. Generate a vector like 1,2,2,3,3,3,4,4,4,4
Solution Stats
Problem Comments
-
18 Comments
function ans = GenerateVector(n)
ans = 1;
for n = 2:n
ans = [ans n*ones(1, n)];
end
could sb explain me why this code is flagged a as a bad one ?? it works !! and another thign in problem definition it is not clearly stated that the solutions must be straight code without writing a function. I wrote a function and it works well to the definition of the problem. then I am getting incorrect information after submission. dear cody team: please write more specific requirements of the problem. you will miss many misunderstandings then.
Your function has to use exactly the same name that is provided in the function template. In this case, the function must be called "you_fcn_name". You wrote a function called "GenerateVector". Change the name of your function and it should pass.
The test suite has been expanded.
Good problem.
Is there any way to avoid the for loop? I really want to but I don't see how right now.
Good one! took some time but finally did it.
Can it be done without a for loop?
Good problem.
HINT:
use command "repelem"
Solution:
A=1:n
B=repelem(A,1:n)
great problem. Interesting for beginners like me.
can we do it without loops?
good
good problem
good
one liner
Incredibly fun problem!
Easy and funny
Great and funny
looks tricky but easy to solve.
Tricky!
oh yeah, it's all coming together
Solution Comments
-
1 Comment
Letsss goooo
-
1 Comment
bit tricky but funny one :)
-
1 Comment
Actually easier than first thought and there may even be simpler solutions than i tried
-
1 Comment
You can help me whit this problem please!
-
1 Comment
tricky
-
2 Comments
Looks tricky.. but easy one
GOOD
-
1 Comment
challenging nice!
-
1 Comment
The suggestion leads to wrong answers because of "ans".
-
1 Comment
It would be nice to know how the leading solution was do to be so small.
-
1 Comment
My solution size is at least 6 times than the leading solution. I would like to be enlightened...
-
1 Comment
what's wrong with my answer? it gives exactly the right answer just not in []
also the test suite says it gives you x but when you use x in the function it doesn't recognize x you have to use n
-
1 Comment
Great problem
-
1 Comment
Brilliant solution without using loops.
-
1 Comment
Funny, I just tested you SO post too, and it has 2 nodes lest without the assignment to ans. I don't get this yet...
-
1 Comment
neat and elegant.
didn't even known about Henkel's matrix
-
3 Comments
could sb please explain me politely why this code has been rated as an incorrect one ? if you paste this in m-file it works !!!
Function name should be your_fcn_name
good
Problem Recent Solvers8162
Suggested Problems
-
3736 Solvers
-
452 Solvers
-
363 Solvers
-
820 Solvers
-
716 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!