Task 3 — Frequency Grouping
Objective
Generate 60 random integer values inside a defined numeric range and classify every distinct value according to how many times it occurs in the generated collection.
The result contains three groups:
- values that occur exactly once
- values that occur exactly twice
- values that occur three or more times
Random Data Generation
Generate exactly:
60
integer values.
Every generated value must satisfy:
value > 20 && value <= 40
Therefore, valid generated integers are:
21 through 40
inclusive.
Store the generated values in:
[]int
Example Generated Data
A partial example could look like:
[]int{
23, 25, 27, 40, 38,
27, 31, 27, 35, 25,
// ...
}
The complete generated slice must contain 60 values.
Function
Create a function that receives the generated []int and separates its distinct values into three frequency groups.
The exact function name is not specified by the original task.
Group 1 — Occurs Once
The first group contains values that appear exactly once in the input.
Condition:
count(value) == 1
For example:
23
40
38
31
may belong to this group if each appears only once in the complete generated collection.
Group 2 — Occurs Twice
The second group contains values that appear exactly twice.
Condition:
count(value) == 2
For example, if:
25
appears exactly two times, it belongs to Group 2.
Group 3 — Occurs Three or More Times
The third group contains values that appear at least three times.
Condition:
count(value) >= 3
For example, if:
27
appears three or more times, it belongs to Group 3.
Result
The function should produce three collections of distinct values.
Conceptually:
[][]int{
uniqueOnce,
uniqueTwice,
uniqueThreeOrMore,
}
Each distinct numeric value should appear only once in its corresponding result group.
Its frequency determines the group, not the number of times it should be repeated in the result.
For example, if 27 occurs five times in the input, the third result group should still contain:
27
only once.
Example
Suppose part of a generated collection contains:
[]int{
23,
25,
27,
40,
38,
27,
31,
27,
25,
}
Within this simplified example:
23 -> 1 occurrence
25 -> 2 occurrences
27 -> 3 occurrences
40 -> 1 occurrence
38 -> 1 occurrence
31 -> 1 occurrence
The corresponding groups would be:
[][]int{
{23, 40, 38, 31},
{25},
{27},
}
Requirements
The task consists of two logical stages.
Stage 1 — Generate Data
Generate:
60
random integer values satisfying:
20 < value <= 40
Stage 2 — Analyze Frequencies
Determine how many times each distinct value occurs and place it into exactly one of the three frequency groups.
Validation
Before frequency analysis, the implementation may verify that:
len(values) == 60
and that every value satisfies:
20 < value <= 40
Values outside this range violate the task input requirements.
Implementation Notes
The original task included 19 inside an abbreviated example of generated values even though the defined generation range is:
value > 20 && value <= 40
The valid specification takes precedence here, so generated values must remain within 21 through 40.
The implementation should count frequencies rather than repeatedly scanning the collection unnecessarily.
The ordering of values inside each result group is not specified by the original task.
If deterministic output is desired, the groups may be sorted in ascending order.