What you're asking about is called a factorial base, and you could just advance the counter with the correct amount when needed. You can read more about it here: http://efesx.com/2009/11/14/enumerating-permutations/ (and at http://marknelson.us/2002/03/01/next-permutation/ as well)
↧