task 8: added algorithm from Wikipedia