Implementation for hibbard and knuth sequence