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. theory needed for a described algorithm

theory needed for a described algorithm

Scheduled Pinned Locked Moved Algorithms
algorithmshelp
9 Posts 4 Posters 0 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.
  • L Offline
    L Offline
    liquid_
    wrote on last edited by
    #1

    The problem is: given a set of numbers: xi > d and xi+1 > xi and xi+1 - xi > d, i=1..N and "distance" d find such the greatest number v which satisfies the condition for each xi-d/2 and xi+d/2 to be entirely included between kv and (k+1)v where k is integer > 0. I found an empiric algorithm first to be evaluated manually in spreadsheet and then I coded it but I am not sure whether it is reliable without some theory.

    B L S 4 Replies Last reply
    0
    • L liquid_

      The problem is: given a set of numbers: xi > d and xi+1 > xi and xi+1 - xi > d, i=1..N and "distance" d find such the greatest number v which satisfies the condition for each xi-d/2 and xi+d/2 to be entirely included between kv and (k+1)v where k is integer > 0. I found an empiric algorithm first to be evaluated manually in spreadsheet and then I coded it but I am not sure whether it is reliable without some theory.

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      The problem is not completely described, is it? I guess "d" is greater than 0. Any further conditions for d? The minimum value for xi-d/2 is Min(xi)-d/2. When d is greater than 2 times the smallest x value, that expression becomes negativ, and there is no v fulfilling the conditions.

      L 1 Reply Last reply
      0
      • B Bernhard Hiller

        The problem is not completely described, is it? I guess "d" is greater than 0. Any further conditions for d? The minimum value for xi-d/2 is Min(xi)-d/2. When d is greater than 2 times the smallest x value, that expression becomes negativ, and there is no v fulfilling the conditions.

        L Offline
        L Offline
        liquid_
        wrote on last edited by
        #3

        Right. I should write: xi > d. I know that it is not solvable in any case of d and set of xi. It would be interesting to find limitations when it is.

        1 Reply Last reply
        0
        • L liquid_

          The problem is: given a set of numbers: xi > d and xi+1 > xi and xi+1 - xi > d, i=1..N and "distance" d find such the greatest number v which satisfies the condition for each xi-d/2 and xi+d/2 to be entirely included between kv and (k+1)v where k is integer > 0. I found an empiric algorithm first to be evaluated manually in spreadsheet and then I coded it but I am not sure whether it is reliable without some theory.

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Are x, d, and v also integers?

          1 Reply Last reply
          0
          • L liquid_

            The problem is: given a set of numbers: xi > d and xi+1 > xi and xi+1 - xi > d, i=1..N and "distance" d find such the greatest number v which satisfies the condition for each xi-d/2 and xi+d/2 to be entirely included between kv and (k+1)v where k is integer > 0. I found an empiric algorithm first to be evaluated manually in spreadsheet and then I coded it but I am not sure whether it is reliable without some theory.

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

            That doesn't make much sense to me. As the set xi is an ordered set, all that matters are the values of the smallest and largest of the xi numbers. So it boils down to: given natural numbers d, min, and max, where

            d < min
            min + d < max
            

            find values k and v such that

            k\*v  < min - d/2
            (k+1)\*v  > max + d/2
            

            which can't be hard to solve, by picking any v that satisfies

            v > max - min + d
            

            then finding k through division. So I'd guess you want something entirely different. :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            L 1 Reply Last reply
            0
            • L Luc Pattyn

              That doesn't make much sense to me. As the set xi is an ordered set, all that matters are the values of the smallest and largest of the xi numbers. So it boils down to: given natural numbers d, min, and max, where

              d < min
              min + d < max
              

              find values k and v such that

              k\*v  < min - d/2
              (k+1)\*v  > max + d/2
              

              which can't be hard to solve, by picking any v that satisfies

              v > max - min + d
              

              then finding k through division. So I'd guess you want something entirely different. :)

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              L Offline
              L Offline
              liquid_
              wrote on last edited by
              #6

              Let me show this on the example: You're given x1=22 x2=50 x3=100 and d=10 We can find v=15 which satisfies this: we can divide the range <0,100(or at least)> into equal intervals of length 15 because our "10" fits in: 1*15 and 2*15 with the middle in 22 i.e. <17,27> 3*15 and 4*15 with the middle in 50 i.e. <45,55> 6*15 and 7*15 with the middle in 100 i.e. <95,105> I hope it's clearer now and excuse me if the latter was not.

              L B 2 Replies Last reply
              0
              • L liquid_

                Let me show this on the example: You're given x1=22 x2=50 x3=100 and d=10 We can find v=15 which satisfies this: we can divide the range <0,100(or at least)> into equal intervals of length 15 because our "10" fits in: 1*15 and 2*15 with the middle in 22 i.e. <17,27> 3*15 and 4*15 with the middle in 50 i.e. <45,55> 6*15 and 7*15 with the middle in 100 i.e. <95,105> I hope it's clearer now and excuse me if the latter was not.

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

                it now sounds like you are accepting (or even requiring) a different k value for each new x sample... if so, I don't know an algorithm that does it right away, however it reminds me of hash function optimisation, maybe a little Google could help you. :)

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                1 Reply Last reply
                0
                • L liquid_

                  Let me show this on the example: You're given x1=22 x2=50 x3=100 and d=10 We can find v=15 which satisfies this: we can divide the range <0,100(or at least)> into equal intervals of length 15 because our "10" fits in: 1*15 and 2*15 with the middle in 22 i.e. <17,27> 3*15 and 4*15 with the middle in 50 i.e. <45,55> 6*15 and 7*15 with the middle in 100 i.e. <95,105> I hope it's clearer now and excuse me if the latter was not.

                  B Offline
                  B Offline
                  Bernhard Hiller
                  wrote on last edited by
                  #8

                  That means d <= v <= x1 - d/2, v must not be a divider of any xi. There is no solution when you set x2=49 or x3=99. Are there some more constraints on the series?

                  1 Reply Last reply
                  0
                  • L liquid_

                    The problem is: given a set of numbers: xi > d and xi+1 > xi and xi+1 - xi > d, i=1..N and "distance" d find such the greatest number v which satisfies the condition for each xi-d/2 and xi+d/2 to be entirely included between kv and (k+1)v where k is integer > 0. I found an empiric algorithm first to be evaluated manually in spreadsheet and then I coded it but I am not sure whether it is reliable without some theory.

                    S Offline
                    S Offline
                    Skippums
                    wrote on last edited by
                    #9

                    So you know the following: 1. d ≤ v ≤ x1 - d/2 2. ∀xn, d/2 ≤ xn % v ≤ v - d/2 My dumb algorithm in C# would be (untested):

                    int FindV(List<int> x, int d) {
                    int halfD = (d + 1) / 2;
                    // Handle odd d by rounding up to the next even
                    d = 2 * halfD;
                    for (int v = x[0] - halfD; v >= d; --v) {
                    int upper = v - halfD;
                    bool solved = true;
                    foreach (int xn in x) {
                    int mod = xn % v;
                    if (mod < halfD || upper < mod) {
                    solved = false;
                    break;
                    }
                    }
                    if (solved) return v;
                    }
                    return -1;
                    }

                    Sounds like somebody's got a case of the Mondays -Jeff

                    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