result:
minimal length:
maximal length:

source (simplified)
source
this program uses formel class