Various algorithms implemented because I should really be doing more important work.