arrays - Find regular intervals in a set of unordered numbers -


i have set of not-unique real numbers read file.

all these numbers generated linear space, is, difference between numbers multiple fixed value, "step" or "grid size" of linear space, say.

each existing value tipically appear many times in file.

my goal find how values spaced, put each (unique) value in array , access value index.

you looking greatest common divisor of numbers. here in python:

def gcd( a, b ):     "greatest common divisor"     while true:         c = % b         if c < 1e-5:             return b         a, b = b, c  def gcdset( a_set ):     "use pairwise gcd find gcd of set"     x = a_set.pop()     total = x     u in a_set:         x = gcd( u, x )         # following step optional,         # sort of stabilization improved accuracy         total = total + u         x = total / round(total/x)      return x  # list want find gcd inputlist = [2239.864226650253, 1250.4096410911607, 1590.1948696485413,     810.0479848807954, 2177.343744595695, 54.3656365691809, 2033.2748076873656,     2074.049035114251, 108.7312731383618, 2188.216871909531]  # turn set rid of duplicates aset = set(inputlist) print(gcdset( aset )) 

if don't have python around can play code here: http://ideone.com/n9xdwa


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -