Why not describe the algorithm you have in mind? It should be pretty easy to figure out, methinks.