Source: https://www.lamsade.dauphine.fr/~sikora/ens/2013/l2/java/poly1314.pdf