Source: https://www.kiteb.net/education/informatique/bac/bacinfo2016/bac-pratique-21052016-algo-corrige4.pdf