Results 1 to 8 of 8

Thread: I finally got it!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    I finally got it!

    I finally understand how to add 2 numbers properly! Try it out yourself!

    Code:
        Function Add(A As Integer, B As Integer) As Integer
            Dim C As Integer = CInt((Math.Sign(A) * Math.Abs(A)).ToString.ToUpper.ToLower)
            Dim D As New List(Of Integer)
            With D
                .Add(CInt(CStr(CInt(CStr(CInt(B.ToString))))))
            End With
            A = A * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 0
            B = CInt(Math.Sqrt(Math.Pow(B, 2))) - ----((((((((((((B))))))))))))
            If True OrElse False Then A = ((((((((((((((((((((((C * 2)))))))))))))))) - --------C))))))
            If True AndAlso A - -1 > A Then B = Convert.ToInt32(D(0) * 2) - Convert.ToInt32(Convert.ToInt64(D(0)))
            Dim E As New With {.Value = A + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + (10000 * 0)}
            Dim F() As Integer = {B}
            A = CInt(C.ToString.ToString.ToString.ToString.ToString.ToString.ToString.ToString)
            B = (((((((((((((((((((((((((((((((((((((((((((((D(0) + D(0) - D(0))))))))))))))))))))))))))))))))))))))))))))))
            Return E.Value + F(0) + (2 * (A + B) - A - B) - (C + D(0))
        End Function

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: I finally got it!

    Where's the recursion?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: I finally got it!

    Where's the recursion?
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: I finally got it!

    Here's the recursion:

    Code:
        Function Add(A As Integer, B As Integer) As Integer
            If A = 0 AndAlso B > 0 Then Return 1 + Add(A, B - 1)
            If A = 0 AndAlso B < 0 Then Return -1 + Add(A, B + 1)
            If A > 0 AndAlso B = 0 Then Return 1 + Add(A - 1, B)
            If A < 0 AndAlso B = 0 Then Return -1 + Add(A + 1, B)
            If A > 0 AndAlso B < 0 Then Return Add(A - 1, B + 1)
            If A < 0 AndAlso B > 0 Then Return Add(A + 1, B - 1)
            If A > 0 AndAlso B > 0 Then Return 2 + Add(A - 1, B - 1)
            If A < 0 AndAlso B < 0 Then Return -2 + Add(A + 1, B + 1)
            If A = 0 AndAlso B = 0 Then Return 0
        End Function
    I tried to improve it, but I kept on getting a StackOverflowException.

    Code:
        Function Add(A As Integer, B As Integer) As Integer
            If A = 0 AndAlso B > 0 Then Return 1 + Add(A, Add(B, -1))
            If A = 0 AndAlso B < 0 Then Return -1 + Add(A, Add(B, 1))
            If A > 0 AndAlso B = 0 Then Return 1 + Add(Add(A, -1), B)
            If A < 0 AndAlso B = 0 Then Return -1 + Add(Add(A, 1), B)
            If A > 0 AndAlso B < 0 Then Return Add(Add(A, -1), Add(B, 1))
            If A < 0 AndAlso B > 0 Then Return Add(Add(A, 1), Add(B, -1))
            If A > 0 AndAlso B > 0 Then Return 2 + Add(Add(A, -1), Add(B, -1))
            If A < 0 AndAlso B < 0 Then Return -2 + Add(Add(A, 1), Add(B, 1))
            If A = 0 AndAlso B = 0 Then Return 0
        End Function

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: I finally got it!

    Quote Originally Posted by NinjaNic View Post
    I tried to improve it, but I kept on getting a StackOverflowException.
    You can find a solution to that here

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: I finally got it!

    Quote Originally Posted by si_the_geek View Post
    You can find a solution to that here
    Good find.
    Last edited by NinjaNic; Jan 15th, 2017 at 12:38 PM. Reason: Found the solution here

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: I finally got it!

    I thought it was going to be a link to an exceptional Stack Overflow thread.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: I finally got it!

    Quote Originally Posted by Shaggy Hiker View Post
    I thought it was going to be a link to an exceptional Stack Overflow thread.
    Me too, to be honest.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width