Problem of mathematical logic

I did my best …

x = N solide

y = NS Porté

5 = Max N solide

Rst = Result

x – 5 = Reste NS

if : (y >= 5)

Then : (Widget STOP)

Else : x – 5 = Rst 1

if : (Rst 1 < 0)

Then : Rst 2 = (Rst1 * -1) ; Rst 3 = (5 – Rst 2) ; Rst4 = (x – Rst 3) ; Rst 5 = (Rst 3 + y)

Else : Rst 5 = y ; Rst 6 = (5 – y) ; Rst 7 = (y + Rst 6) ; y = Rst 7 ; x = (Reste NS + Rst 5)

if : (Rst 5 > 5)

Then : Rst 8 = (Rst 5 – 5) ; Rst 9 = (Rst 5 – Rst 8) ; x = (Rst 4 + Rst 8)

Else : y = Rst 5 ; x = Rst 4