Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Danilin without the GoTo's
#5
The original code was too simple and indented so I took the liberty of complexifying it for you:
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)
Reply


Messages In This Thread
Danilin without the GoTo's - by bplus - 02-28-2026, 10:23 PM
RE: Danilin without the GoTo's - by CharlieJV - 03-01-2026, 02:20 AM
RE: Danilin without the GoTo's - by bplus - 03-01-2026, 05:22 AM
RE: Danilin without the GoTo's - by SMcNeill - 03-01-2026, 02:23 AM
RE: Danilin without the GoTo's - by luke - 03-01-2026, 11:23 AM
RE: Danilin without the GoTo's - by bplus - 03-01-2026, 02:00 PM
RE: Danilin without the GoTo's - by SMcNeill - 03-01-2026, 03:19 PM
RE: Danilin without the GoTo's - by CharlieJV - 03-01-2026, 06:37 PM
RE: Danilin without the GoTo's - by bplus - 03-01-2026, 05:15 PM
RE: Danilin without the GoTo's - by bplus - 03-01-2026, 07:05 PM
RE: Danilin without the GoTo's - by Kernelpanic - 03-01-2026, 07:18 PM
RE: Danilin without the GoTo's - by CharlieJV - 03-01-2026, 07:44 PM
RE: Danilin without the GoTo's - by Kernelpanic - 03-01-2026, 10:02 PM
RE: Danilin without the GoTo's - by CharlieJV - 03-01-2026, 11:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star MazeBall & DAV & Danilin Solve of Labyrinth DANILIN 1 842 10-12-2024, 11:57 AM
Last Post: DANILIN

Forum Jump:


Users browsing this thread: 1 Guest(s)