Create iter_helper interesting_repetition
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 22 Jun 2018 12:09:30 +0000 (14:09 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 8 Oct 2018 07:31:37 +0000 (09:31 +0200)
src/iter_helpers.py

index f02bef7..36c2991 100644 (file)
@@ -43,3 +43,34 @@ def pairwise(iterable):
     a, b = it.tee(iterable)
     next(b, None)
     return zip(a, b)
+
+
+def interesting_repetition(rep):
+    """Return True for indices [1,2,3,5,7,10,15,20,30,50,75,100,150,200,...]"""
+    if rep in (0, 1, 2, 3, 5, 7):
+        return True
+    elif rep < 10:
+        return False
+    elif rep in (10, 15, 20, 30, 50, 75):
+        return True
+    elif rep < 100:
+        return False
+    elif rep in (100, 150, 200, 300, 500, 750):
+        return True
+    elif rep < 1000:
+        return False
+    elif rep in (1000, 1500, 2000, 3000, 5000, 7500):
+        return True
+    elif rep < 10000:
+        return False
+    base = 100
+    while True:
+        base *= 10
+        if rep in (base * num for num in (10, 15, 20, 30, 50, 75)):
+            return True
+        elif rep < base*100:
+            return False
+
+    # could try to do this with math.log (e.g. number of digits is
+    # 1+math.floor(math.log(rep, 10))), but quickly get into problems with
+    # precision (e.g. log(1000, 10) = 2.9999999999996 should be 3)