Impressive!
You know what would be nice? If you could go and comment your code a bit so that it would become more understandable for beginners.
Too often I see little pieces of code that have potential to serve as learning examples but don't have any comments and therefore are not suitable for learning for beginners. Well not without the need to load this code into debugger and walk through it step by step.