' Cas général
ee = 9999: vv = 9999: v = 1: i(v) = 1: j(v) = 2: o(v) = 0
Do
If o(v) < 4 Then
Opsuiv: ' Opération suivante
o(v) = o(v) + 1
Select Case o(v)
Case 1 ' -
a(v + 1, i(v)) = Abs(a(v, i(v)) - a(v, j(v)))
If a(v + 1, i(v)) = 0 Then GoTo Opsuiv
Case 2 ' *
a(v + 1, i(v)) = a(v, i(v)) * a(v, j(v))
If a(v + 1, i(v)) >= 10000000 Then GoTo Opsuiv
Case 3 ' /
If a(v, i(v)) >= a(v, j(v)) Then u = a(v, i(v)) / a(v, j(v)) Else u = a(v, j(v)) / a(v, i(v))
If Int(u) = u Then a(v + 1, i(v)) = u Else GoTo Opsuiv
Case 4 ' +
a(v + 1, i(v)) = a(v, i(v)) + a(v, j(v))
End Select
' Ecart avec le résultat
e = Abs(a(v + 1, i(v)) - zz)
' Mémorisation
If (e < ee) Or (e = ee And v < vv) Then
ee = e: vv = v
For k = 1 To NN
If k < NN Then ii(k) = i(k): jj(k) = j(k): oo(k) = o(k)
For l = 1 To NN: aa(k, l) = a(k, l): Next l
Next k
End If
If v < NNM1 Then
For l = j(v) To NN - v: a(v + 1, l) = a(v, l + 1): Next l
v = v + 1: i(v) = 1: j(v) = 2: o(v) = 0
End If
ElseIf j(v) <= NN - v Then
a(v + 1, j(v)) = a(v, j(v))
j(v) = j(v) + 1: o(v) = 0
ElseIf i(v) < NN - v Then
a(v + 1, i(v)) = a(v, i(v))
i(v) = i(v) + 1: j(v) = i(v) + 1: o(v) = 0
For l = j(v) To NN - v: a(v + 1, l) = a(v, l + 1): Next l
Else
v = v - 1: If v = 0 Then Exit Do
End If
Loop