The original code was too simple and indented so I took the liberty of complexifying it for you:
It's only about 7 times slower than b+'s original (with C++ optimizations turned on)
Code: (Select All)
$Checking:Off
Const NUM_VALUES = 10
Type vec3
a As Integer
b As Integer
c As Integer
End Type
Function next_vec3 (v As vec3)
next_vec3 = _TRUE
v.c = (v.c + 1) Mod NUM_VALUES
If v.c = 0 Then
v.b = (v.b + 1) Mod NUM_VALUES
If v.b = 0 Then
v.a = (v.a + 1) Mod NUM_VALUES
next_vec3 = v.a <> 0
End If
End If
End Function
Function next_muldiff (v As vec3, target As Integer)
Do
If next_vec3(v) = 0 Then Exit Function
If v.a * v.b - v.c = target Then
next_muldiff = _TRUE
Exit Function
End If
Loop
End Function
Function next_sum (v As vec3, target As Integer)
Do
If next_vec3(v) = 0 Then Exit Function
If v.a + v.b + v.c = target Then
next_sum = _TRUE
Exit Function
End If
Loop
End Function
Function next_divsum (v As vec3, target As Integer)
Do
If next_vec3(v) = 0 Then Exit Function
If v.a / v.b + v.c = target Then
next_divsum = _TRUE
Exit Function
End If
Loop
End Function
Sub zero_vec3 (v As vec3)
v.a = 0
v.b = 0
v.c = 0
End Sub
Sub print_vec3 (v As vec3)
Print v.a; v.b; v.c
End Sub
Dim As vec3 x, y, z
t# = Timer(0.001)
Do While next_muldiff(x, 4)
zero_vec3 y
y.a = 1
Do While next_sum(y, 8)
zero_vec3 z
z.b = 1
Do While next_divsum(z, 8)
If x.a / y.a + z.a = 9 _AndAlso _
x.b + y.b + z.b = 8 _AndAlso _
x.c + y.c - z.c = 6 Then
print_vec3 x
print_vec3 y
print_vec3 z
Print
End If
Loop
Loop
Loop
Print Timer(0.001) - t#It's only about 7 times slower than b+'s original (with C++ optimizations turned on)

