My solution is not the first; however, I think, it is rather universal and very short - less than 20 lines of the code... ...