Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Need some intelligent people...

Need some intelligent people...

Scheduled Pinned Locked Moved Algorithms
question
9 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paddy Boyd
    wrote on last edited by
    #1

    It's been a long time since i did any really hard maths and a friend of mine just asked me the following question: "How can I easily find all possible solutions for 3125r = 1024x - 8404 where r and x are both integers, and r is divisible by 5" Any very intelligent people out there who know of an answer?

    L R C 3 Replies Last reply
    0
    • P Paddy Boyd

      It's been a long time since i did any really hard maths and a friend of mine just asked me the following question: "How can I easily find all possible solutions for 3125r = 1024x - 8404 where r and x are both integers, and r is divisible by 5" Any very intelligent people out there who know of an answer?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, there is an infinite number of solutions, given by: r=1020+5120t x=3121+15625t where any value of t will do. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      P 2 Replies Last reply
      0
      • L Luc Pattyn

        Hi, there is an infinite number of solutions, given by: r=1020+5120t x=3121+15625t where any value of t will do. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        P Offline
        P Offline
        Paddy Boyd
        wrote on last edited by
        #3

        I thought there would be any number of solutions (with no particular grounding or proof). But that's certainly a faster way of finding them...

        1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, there is an infinite number of solutions, given by: r=1020+5120t x=3121+15625t where any value of t will do. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          P Offline
          P Offline
          Paddy Boyd
          wrote on last edited by
          #4

          Would it be an impudent question to ask how you arrived at this solution? Trying to work back from your solution leaves me a bit stumped...

          L 1 Reply Last reply
          0
          • P Paddy Boyd

            Would it be an impudent question to ask how you arrived at this solution? Trying to work back from your solution leaves me a bit stumped...

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi Paddy, there are several ways to find the solution(s) of ax+by=c. First of all a single, linear equation in two variables has either no solution at all (say 2x + 4y = 1) or an infinite number, by adding the second coefficient to the first number and subtracting the first coef from the second number. So the main problem is to find a first solution. Method 1: write a little prog, assume x=u+bt and y=v-at and have it try a lot of values u (keep t at 0) and calculate real v until it happens to be integer. Method 2: follow the strict mathematical approach; that's what you would need if decent code is required to solve such problems in general Method 3: the way in-between, with a couple of shortcuts, the ideal way to solve a single problem manually. Like so: 3125r = 1024x - 8404 with constraint r=multiple of 5 lets try to replace variables by other variables and reduce the size of the constants: right hand side is multiple of 4, hence r must be multiple of 20, say r=20a 3125 * 20a = 1024x - 8404 15625a = 256x - 2101 lets ignore all multiples of the smallest coef, 256 15625=61*256+9 -2101=-9*256+203 9a = 203 (modulo 256) try a couple of numbers 203 + 256k until a multiple of 9 is found; this is bound to happen in 9 tries ! one immediately sees a solution is a=(203+256)/9=51 (this is where the mathematician would go more formally !) hence r=1020, then calculate the x that goes with it, and add one variable t with the right coefs. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


            P 1 Reply Last reply
            0
            • L Luc Pattyn

              Hi Paddy, there are several ways to find the solution(s) of ax+by=c. First of all a single, linear equation in two variables has either no solution at all (say 2x + 4y = 1) or an infinite number, by adding the second coefficient to the first number and subtracting the first coef from the second number. So the main problem is to find a first solution. Method 1: write a little prog, assume x=u+bt and y=v-at and have it try a lot of values u (keep t at 0) and calculate real v until it happens to be integer. Method 2: follow the strict mathematical approach; that's what you would need if decent code is required to solve such problems in general Method 3: the way in-between, with a couple of shortcuts, the ideal way to solve a single problem manually. Like so: 3125r = 1024x - 8404 with constraint r=multiple of 5 lets try to replace variables by other variables and reduce the size of the constants: right hand side is multiple of 4, hence r must be multiple of 20, say r=20a 3125 * 20a = 1024x - 8404 15625a = 256x - 2101 lets ignore all multiples of the smallest coef, 256 15625=61*256+9 -2101=-9*256+203 9a = 203 (modulo 256) try a couple of numbers 203 + 256k until a multiple of 9 is found; this is bound to happen in 9 tries ! one immediately sees a solution is a=(203+256)/9=51 (this is where the mathematician would go more formally !) hence r=1020, then calculate the x that goes with it, and add one variable t with the right coefs. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


              P Offline
              P Offline
              Paddy Boyd
              wrote on last edited by
              #6

              Thanks very much for your time :o)

              1 Reply Last reply
              0
              • P Paddy Boyd

                It's been a long time since i did any really hard maths and a friend of mine just asked me the following question: "How can I easily find all possible solutions for 3125r = 1024x - 8404 where r and x are both integers, and r is divisible by 5" Any very intelligent people out there who know of an answer?

                R Offline
                R Offline
                Russell
                wrote on last edited by
                #7

                Paddy Boyd wrote:

                r is divisible by 5

                Then use r=5*y, then:

                3125*5*y = 1024x - 8404

                where y and x are both integers

                It is a nice start point


                Russell

                1 Reply Last reply
                0
                • P Paddy Boyd

                  It's been a long time since i did any really hard maths and a friend of mine just asked me the following question: "How can I easily find all possible solutions for 3125r = 1024x - 8404 where r and x are both integers, and r is divisible by 5" Any very intelligent people out there who know of an answer?

                  C Offline
                  C Offline
                  cp9876
                  wrote on last edited by
                  #8

                  Just in case Luc's asleep (seems to be never) you could use this applet[^] and solve -1024x + 15625y + 8404 = 0 then use r = 5y. If you tick the box 'Step-by-step' it even shows all working! The source code for this applet is 3742 lines long! (mostly to do with the quadratic problem I guess)


                  Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                  L 1 Reply Last reply
                  0
                  • C cp9876

                    Just in case Luc's asleep (seems to be never) you could use this applet[^] and solve -1024x + 15625y + 8404 = 0 then use r = 5y. If you tick the box 'Step-by-step' it even shows all working! The source code for this applet is 3742 lines long! (mostly to do with the quadratic problem I guess)


                    Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    cp9876 wrote:

                    seems to be never

                    Really? Gee I must be sleeptyping again. :laugh:

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups