Problem 55. Counting Sequence
Given a vector x, find the "counting sequence" y.
A counting sequence is formed by "counting" the entries in a given sequence.
For example, the sequence
x = 5, 5, 2, 1, 1, 1, 1, 3
can be read as
Two 5's, one 2, four 1's, one 3
which translates to
y = 2, 5, 1, 2, 4, 1, 1, 3
So y is the counting sequence for x.
For this problem, all elements in the sequences x and y will be in the range from 1 to 9.
Solution Stats
Problem Comments

12 Comments
The problem does not define correct solution if same number is not in consecutive order, like x = [5 5 2 1 1 5 3]; Should it be three 5's, or two 5's then one 5? If it's an encoding problem the correct solution should be the last, right?
Typical DPCM encoding removes the DC and thus starts at 0, not 1. An 11% enhancement in encoding.
Good problem.
Most of the solutions with UNIQUE don't work when same number is not in consecutive order.
in the new test case 5, with x=[1 2 2 1], the test suite answer is [2 1 2 2] (two 1's, two 2's). I would expect the correct answer to be [1 1 2 2 1 1] (one 1, two 2's, one 1). I guess I am misinterpreting the question?
No. you are right. The test case 5 is wrong.
My mistake guys. Sorry about that. By the way, these comments are very helpful for adding (and fixing) bad test cases. Thanks for taking the time to comment.
Test case 5 answer is wrong. the correct answer is [2 1 2 2]. Change the test case 5 answer
test case 5 answer is wrong
Just to clarify: test case 5 isnt wrong.
wow, last test case is so fun!
This only took me a few minutes until I saw Case 5 haha! Fun and mind boggling
Solution Comments
Show commentsProblem Recent Solvers1811
Suggested Problems

Sum all integers from 1 to 2^n
13635 Solvers

2122 Solvers

491 Solvers

Who is the smartest MATLAB programmer?
729 Solvers

Convert a Cell Array into an Array
1379 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!