Task 2 — Multi-Dimensional Value Search
Objective
Create a function that searches a two-dimensional collection of float64 values and returns every element that is greater than a specified input value.
For every matched element, the function must also return information about:
- the value that was found
- the list in which the value was found
- the position of the value inside that list
Input
The function has two input arguments.
The first argument is a two-dimensional collection of float64 values:
[][]float64
Example:
data := [][]float64{
{3.2, 5.4},
{6.3, 1.4},
{2.5, 6.5},
}
The second argument is a float64 value that will be used as the comparison threshold.
For example:
4.8
The function must find all elements whose value is greater than the provided threshold.
Result Type
The function must return a collection of Message structures.
The Message structure is defined as:
type Message struct {
Value float64
List int
Position int
}
The fields have the following meaning:
Value— the value that was foundList— the number of the list in which the value was foundPosition— the position of the value inside that list
Function
The function is named:
FindAllGreaterThen(...)
The function receives:
two-dimensional float64 data
+
float64 threshold
and returns:
[]Message
Requirements
Iterate through all values in the provided two-dimensional collection.
For each value:
- Compare it with the provided threshold.
- If the value is greater than the threshold, create a
Message. - Store the matched value in
Message.Value. - Store the number of the containing list in
Message.List. - Store the position of the value inside that list in
Message.Position. - Add the
Messageto the result collection.
Only values strictly greater than the threshold should be returned.
Example Data
Given:
data := [][]float64{
{3.2, 5.4},
{6.3, 1.4},
{2.5, 6.5},
}
the positions can be represented as:
List 1:
Position 1 -> 3.2
Position 2 -> 5.4
List 2:
Position 1 -> 6.3
Position 2 -> 1.4
List 3:
Position 1 -> 2.5
Position 2 -> 6.5
The task uses list and position numbering starting from 1.
Case 1
Call:
FindAllGreaterThen(data, 4.8)
Values greater than 4.8 are:
5.4
6.3
6.5
Their locations are:
5.4 -> List 1, Position 2
6.3 -> List 2, Position 1
6.5 -> List 3, Position 2
Expected Result
[]Message{
{5.4, 1, 2},
{6.3, 2, 1},
{6.5, 3, 2},
}
Case 2
Call:
FindAllGreaterThen(data, 5.5)
Values greater than 5.5 are:
6.3
6.5
Their locations are:
6.3 -> List 2, Position 1
6.5 -> List 3, Position 2
Expected Result
[]Message{
{6.3, 2, 1},
{6.5, 3, 2},
}
Position Numbering
Although Go slices are indexed from 0, the expected task result uses list and position numbering starting from 1.
For example:
data[0][1]
contains:
5.4
but the expected task representation is:
List = 1
Position = 2
The implementation must therefore preserve the numbering convention demonstrated by the expected results.
Implementation Notes
The function should work with other valid two-dimensional float64 collections and threshold values.
The implementation should not depend on the dimensions or values used in the examples.
All nested lists should be processed, and every matching value should be included in the returned collection.
The ordering of the returned messages should follow the traversal order of the input data, as demonstrated by the original examples.