Hi Petras,

try this as a starting point

```
using System.Linq;
private void RunScript(DataTree<double> data, double threshold, ref object A)
{
A = GroupSimilarNumbers(data, threshold);
}
// <Custom additional code>
public DataTree<double> GroupSimilarNumbers(DataTree<double> data, double threshold)
{
DataTree<double> Out = new DataTree<double>();
for (int i = 0; i < data.BranchCount; i++)
{
Dictionary<double, double> groups = new Dictionary<double, double>();
for (int j = 0; j < data.Branches[i].Count - 1; j++)
{
double val = data.Branches[i][j];
double nextVal = data.Branches[i][j + 1];
if(Similar(val, nextVal, threshold))
{
if(!groups.ContainsValue(val))
groups.Add(val, val);
}
if(groups.Count > 0)
{
foreach (KeyValuePair<double, double> entry in groups)
{
if(Similar(val, entry.Value, threshold))
{
if(!groups.ContainsValue(val))
{
groups.Add(val, val);
break;
}
}
if(Similar(nextVal, entry.Value, threshold))
{
if(!groups.ContainsValue(nextVal))
{
groups.Add(nextVal, nextVal);
break;
}
}
}
}
}
Out.AddRange(groups.Select(a => a.Value).ToArray(), new GH_Path(i));
}
return Out;
}
public bool Similar(double a, double b, double threshold)
{
return Math.Abs((a - b)) <= threshold;
}
```

**Important Note: The algorithm would be much simpler if all the branches are sorted before hand. There is actually a small bug in this version because of this. So just sort the data before hand.**