VS 2015 3 letter brute force-VBForums

# Thread: 3 letter brute force

1. ## 3 letter brute force

Using Brute Force and Nested Loops Find all answers to AAA+BBB+CCC+DDD=ABCD where each letter stands for a digit 0-9.

I am stuck at the solution.
Code:
```Public Class Test
Public Shared Sub Main()
DIM AAA,BBB,CCC,DDD, ABCD As Integer
For AAA = 0 to 9
For BBB = 0 to 9
For CCC = 0 to 9
For DDD = 0 to 9
If AAA+BBB+CCC+DDD=ABCD Then
String.Format("{0:D}, {1:D}, {2:D},{3:D}", AAA, BBB, CCC, DDD))
End If

Next DDD
Next CCC
Next BBB
Next AAA
End Sub
End Class```

2. ## Re: 3 letter brute force

Welcome to the forums. I edited your post to add [CODE][/CODE] tags. You can do this by pressing the # button and pasting the code between the resulting tags, or pasting the code, then highlighting it and pressing the # button.

As to the question, I'd say the problem is in the If statement, but I'm not quite sure what you want it to do. As it stands, you never set ABCD to anything, so it is 0. Therefore, the only time that If statement is ever true is if AAA+BBB+CCC+DDD is 0, which is only going to happen when each of those variables is 0.

Therefore, if the goal was to have somebody put in a value for ABCD and show all the combinations that add up to that, then all you'd have to do is add something before the For loop to have the user enter a value for ABCD.

3. ## Re: 3 letter brute force

Thanks... After much reading...Just found that I was doing this completely wrong...

4. ## Re: 3 letter brute force

Your loop counters should be A, B, C and D. Your If statement would then be along the lines of:
vb.net Code:
`If A * 111 + B * 111 + C * 111 + D * 111 = A * 1000 + B * 100 + C * 10 + D Then    'Match found.End If`

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured

Click Here to Expand Forum to Full Width

Survey posted by VBForums.