From: Christian Herdtweck Date: Fri, 22 Jun 2018 12:09:30 +0000 (+0200) Subject: Create iter_helper interesting_repetition X-Git-Tag: v1.3~18 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=7b555a23787c5d68812dbc8d0e970024fc544910;p=pyi2ncommon Create iter_helper interesting_repetition --- diff --git a/src/iter_helpers.py b/src/iter_helpers.py index f02bef7..36c2991 100644 --- a/src/iter_helpers.py +++ b/src/iter_helpers.py @@ -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)