Still needing HELPbut should have posted this

  • Context: High School 
  • Thread starter Thread starter strack22
  • Start date Start date
Click For Summary
SUMMARY

This discussion centers on solving a mathematical puzzle involving unique digits from 1 to 9. The problem is framed as two equations: ABC + DEF = GHI and ADG + BEH = CFI. A user shares a Visual Basic program that efficiently finds multiple solutions by ensuring digit uniqueness, reducing the solution space significantly. The program outputs several valid combinations, demonstrating the effectiveness of computational approaches in solving such puzzles.

PREREQUISITES
  • Understanding of basic algebraic equations
  • Familiarity with programming concepts, particularly recursion
  • Knowledge of Visual Basic programming language
  • Concept of unique digit constraints in mathematical puzzles
NEXT STEPS
  • Explore advanced recursion techniques in Visual Basic
  • Learn about combinatorial algorithms for solving digit-based puzzles
  • Investigate optimization strategies for reducing solution spaces in programming
  • Study the implementation of backtracking algorithms in problem-solving
USEFUL FOR

Mathematicians, programmers, puzzle enthusiasts, and anyone interested in algorithmic problem-solving and computational mathematics.

strack22
Messages
3
Reaction score
0
there is a second part to my original puzzle...sorry

So, IF ABC plus DEF equals GHI THEN,

ADG, plus BEH equals CFI...

Please any takers on this...it is driving me CRAZY !

the teasers are listed across if that helps
A B C A D G
+D E F + B E H
_______ ________
G H I C F I

Not sure if you will see it correctly ...sorry
 
Mathematics news on Phys.org
The usual way to solve these puzzles is to turn your two equations into many. For example, based on the small digits: (C + F) mod 10 = (G + H) mod 10 = I. However, whenever I see these puzzles I always just write a computer program to solve them by doing a case-by-case. Here is the output of the program I wrote (notice how there are TWO answers, but that they are very similar):
Code:
718236954     718 + 236 = 954             729 + 135 = 864
729135864     729 + 135 = 864             718 + 236 = 954

and the program:

Code:
Dim d(1 To 9) As Long

Private Sub Main()
    Call testDigit(1) 'start the recursion on the first digit
End Sub
Private Sub testDigit(ByVal index As Long)
Dim a As Long
    For a = 1 To 9
        If digitsContain(a) = False Then 'make sure the digit is unique
            d(index) = a 'try this digit in this position
            If index < 9 Then
                Call testDigit(index + 1) 'go to next digit if we're not at the last one
            ElseIf isValid Then 'if we're at the last digit, check the answer
                printDigits
            End If
        End If
    Next a
    d(index) = 0 'reset digit
End Sub
Private Function digitsContain(ByVal n As Long) As Boolean
Dim a As Long
    'Check if the digit 'n' is already used
    For a = 1 To 9
        If d(a) = n Then
            digitsContain = True
        End If
    Next a
End Function
Private Function isValid() As Boolean
    'make sure the digits match the program
    isValid = CBool(CLng(d(1) & d(2) & d(3)) + CLng(d(4) & d(5) & d(6)) = CLng(d(7) & d(8) & d(9)))
    isValid = isValid And CBool(CLng(d(1) & d(4) & d(7)) + CLng(d(2) & d(5) & d(8)) = CLng(d(3) & d(6) & d(9)))
End Function
Private Sub printDigits()
Dim a As Long
Dim s As String
    For a = LBound(d) To UBound(d)
        s = s & d(a)
    Next a
    Debug.Print s, d(1) & d(2) & d(3) & " + " & d(4) & d(5) & d(6) & " = " & d(7) & d(8) & d(9), d(1) & d(4) & d(7) & " + " & d(2) & d(5) & d(8) & " = " & d(3) & d(6) & d(9)
End Sub

Originally I missed the 'unique 1-9' requirement and was finding hundreds of answers. But when I realized they had to be unique the problem space went from a billion possibilities to 362880 possibilities, so it turned out much better!
 
Last edited:
omg...THANK YOU so much...I was trying to figure it out but just assumed that no number would equal more than 10..I was so focused in that respect, I never entertained any other possibilites...geez...but thank you sooo much!
 
Alkatran said:
The usual way to solve these puzzles is to turn your two equations into many. For example, based on the small digits: (C + F) mod 10 = (G + H) mod 10 = I. However, whenever I see these puzzles I always just write a computer program to solve them by doing a case-by-case. Here is the output of the program I wrote (notice how there are TWO answers, but that they are very similar):
Code:
718236954     718 + 236 = 954             729 + 135 = 864
729135864     729 + 135 = 864             718 + 236 = 954

Hm. I wrote a program that found 4 solutions:

Code:
ABCDEFGHI    ABC + DEF = GHI    ADG + BEH = CFI
146583729    146 + 583 = 729    157 + 482 = 639
157482639    157 + 482 = 639    146 + 583 = 729
718236954    718 + 236 = 954    729 + 135 = 864
729135864    729 + 135 = 864    718 + 236 = 954

And a few more if you include 0 (I didn't catch where 0 wasn't a valid option?):

Code:
ABCDEFGHI    ABC + DEF = GHI    ADG + BEH = CFI
326584910    326 + 584 = 910    359 + 281 = 640
348562910    348 + 562 = 910    359 + 461 = 820
359281640    359 + 281 = 640    326 + 584 = 910
359461820    359 + 461 = 820    348 + 562 = 910

And even a few more if you let 0 be a leading digit (which is bad form!)

Code:
ABCDEFGHI    ABC + DEF = GHI    ADG + BEH = CFI
023594617    023 + 594 = 617    056 + 291 = 347
023695718    023 + 695 = 718    067 + 291 = 358
045876921    045 + 876 = 921    089 + 472 = 561
056291347    056 + 291 = 347    023 + 594 = 617
067291358    067 + 291 = 358    023 + 695 = 718
067854921    067 + 854 = 921    089 + 652 = 741
089472561    089 + 472 = 561    045 + 876 = 921
089652741    089 + 652 = 741    067 + 854 = 921

DaveE
 
Interestingly, when I run the program again I get all four answers. I must have missed them somehow.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
6
Views
1K
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K