This is not a VB.NET question. If you have the algorithm and you need help to implement it in VB.NET, THAT is a suitable question for this forum.