<-- Previous || Up || Next -->

Go Figure Function
Math Probability Class

Public Function GoFigure( _
      ByVal vOne As Byte _
    , ByVal vTwo As Byte _
    , ByVal vThree As Byte _
    , ByVal vFour As Byte _
    , ByVal vResult As Long _
    , Optional ByVal vMaxTries As Variant _
    ) As String

Go Figure Puzzle Solver
Return a string expression which is one solution to the given "Go Figure" puzzle.
There may be several solutions, but this function will return the first one that it finds.

Summary: In Go Figure, you are presented with four numbers, which when combined using some combination of the four basic mathematical operators (+, -, *, /), yield the specified result. The object of the game is to arrange the number with the appropriate mathematical operators so that when the expression is evaluated (with left-to-right precedence in the case of this function) it equals the given result.
    Rnd(-1) = 0.224007
    GoFigure(2, 7, 7, 7, 9) = "7+2+7-7"
    GoFigure(2, 2, 6, 7, 6) = "7+2-6*2"
    GoFigure(2, 5, 6, 6, 360) = "5*6*6*2"
    GoFigure(5, 5, 8, 9, 315) = "5*8-5*9"
    GoFigure(2, 4, 7, 8, 3) = "4+8-2-7"
    GoFigure(1, 1, 5, 5, 26) = "5*5*1+1"
Note: The call to the Visual Basic Rnd function in the above example seeds the Visual Basic random number generator so that the sample results can be reproduced. There is generally no need to call the Rnd function within your programs since Entisoft Tools initializes the Visual Basic random number generator once with "Randomize" statement.
See also:
    RandomLongGenerator Function
vOne, vTwo, vThree, vFour: Four numbers which, when combined using some combination of +, -, *, and /, result in vResult.
vResult: The result to which the puzzle solution must evaluate.
vMaxTries: The maximum number of tries that the function should use to find a solution. vMaxTries defaults to 32,000 if it is missing or Null or cannot be fixed up to a number.

BIG Note: This function currently only returns expressions whose evaluation with left-to-right precedence yields vResult. This function cannot currently solve GoFigure puzzles which use the algebraic precedence for evaluating expressions. With algebraic precedence, multiplication and division is performed first (left-to-right), and addition and subtraction is performed next (again, left-to-right).
Note: This function has restrictive argument types to avoid argument fix-up overhead, therefore it does not support multi-valued logic.
Algorithm: This function is NP-Random, and not particularly well optimized, so it might take it several seconds to find a valid solution. Also, it may never find a solution within the specified maximum number of tries, or if its arguments are inconsistent and thus have no solution.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.