The specification code for base algorithm. Just for fun.