Use exactly the same algorithm you'd use with a string of beads or popcorn, at your kitchen table. Simple is fast.