Adding/Subtracting to 100

I need to find out a way to figure out how to figure every way to get to 100
like
1+23-45+67-8+9 (thats not equal = 100)
but stuff like that.. in order.. allowing any amount of numbers.. 1-9 in that order
so like
1+2+3
12+3
1+23
123+
etc.. for both + and -...

i have no idea where to start from


to those who think this is a homework problem: it was a problem we had in class today, i spent along time figuring a correct answer and I just found it by trial and error and it took a long time. teacher said there was 12 different answers and im just wondering as to what they are
LVL 1
spearman123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbruntonCommented:
That's a programming task.

Nice one though.  Very messy to do.

Generally its some sort of loop like

for i := 1 to 9 do
  for j := 2 to 8 do
       for K := 3 to 7 do
             { do something here and test the result.  If it's a 100 you've found an answer }

The for loops here have no relevance, they're just for show.

0
mlmccCommented:
An interesting problem.  Let me make sure I understand it correctly.

You put the digits

1   2   3   4   5    6    7    8     9


Now you can add as many + and - as you want between digits.  The digits cannot be swapped.  If you don't put one in then the two (or more) digits are put together.  Evaluate the expression to see if it is 100.

So
1 + 23 - 45 + 6 + 7 + 8 + 9 is legitimate though no 100
while
1 + 32 - 45 + 6 + 7 + 8 + 9 is not legitimate

mlmcc
0
spearman123Author Commented:
correct
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

crypticfigureCommented:
output: ('+' starts and blank starts are the same)
123+45-67+8-9
123+4-5+67-89
123-45-67+89
123-4-5-6-7+8-9
12+3+4+5-6-7+89
12+3-4+5+67+8+9
12-3-4+5-6+7+89
1+23-4+56+7+8+9
1+23-4+5+6+78-9
1+2+34-5+67-8+9
1+2+3-4+5+6+78+9
+123+45-67+8-9
+123+4-5+67-89
+123-45-67+89
+123-4-5-6-7+8-9
+12+3+4+5-6-7+89
+12+3-4+5+67+8+9
+12-3-4+5-6+7+89
+1+23-4+56+7+8+9
+1+23-4+5+6+78-9
+1+2+34-5+67-8+9
+1+2+3-4+5+6+78+9
-1+2-3+4+5+6+78+9




Private Sub Command1_Click()

    startstring = "123456789"
    spaces = Len(startstring)
   
   
    '9 spaces before, each one can have a plus or minus, or nothing (joined) before it.
   

   
    On Error Resume Next
   
    Dim placedat() As Integer
    ReDim placedat(9)
   
   
    'set all to zero instead of undefined
    For a = 1 To 9
        placedat(a) = 0
    Next a
   
   
    '[(0-8)], each space having 1 through 3 now you go through each one:
    '000000000
    '000000001
    '000000002
    '000000010
    '000000011
   
   
    'endless loop
    While 1 = 1
   

        'add one to the end
        placedat(9) = placedat(9) + 1
       
        'go through each place and if it became a 3, then increment the one beside it
        'and set it to 0, as in 08 09 10 11 12
        For b = 1 To 9
        For a = 1 To 9
            If placedat(a) > 2 Then
           
            If a = 1 Then
                Exit Sub 'if you increment one left to the very last one, then you're done
            Else
                placedat(a - 1) = placedat(a - 1) + 1
                placedat(a) = 0
            End If
           
            End If
        Next a
        Next b
       
       
       
        'now you want to find the sum of all terms.
        'every time you get a full term, signalled by either the start of the
        'next term or getting to the end, then add that term to the main sum
        Dim outSum As Long
       
        outSum = 0
       
        Dim outTerm As String 'to find the term, you make a string var.
        outTerm = ""
        For a = 1 To 9 'go through each 'space'
       
       
       
           
           
            Select Case placedat(a)
           
            Case 0 'nothing
                'if nothing then add it to the term
                outTerm = outTerm & Mid(startstring, a, 1) '
            Case 1 '+
               
                outSum = outSum + CDbl(outTerm) 'add old term to final sum
                outTerm = "+" & Mid(startstring, a, 1) 'start a new term

            Case 2 '-
               
                outSum = outSum + CDbl(outTerm) 'add old term to final sum
                outTerm = "-" & Mid(startstring, a, 1) ' start a new term

            End Select
           
           
        Next a
       
        outSum = outSum + CDbl(outTerm) 'add the remaining term to final sum
       
       
        If outSum = 100 Then   'check if its 100 and print it out
            temp = ""
            For z = 1 To 9
                temp = temp & ct(placedat(z)) & Mid(startstring, z, 1)
            Next z
            PrintOut (temp & " ")
           
        End If
       
   
    Wend
   

End Sub


Public Function ct(num As Integer) As String
    ct = ""
    If num = 1 Then ct = "+"
    If num = 2 Then ct = "-"
End Function

Public Sub PrintOut(data As String)
   
    text1.Text = text1.Text & data & vbCrLf
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spearman123Author Commented:
wow thanks alot!
0
crypticfigureCommented:
np

sorry bout the messy code tho... geeze I must have been intoxicated when I wrote that
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.