I’m sure ive had this in school before, but i cant remember what is this thing called as.
I have arbitrary number and i need to know how many times i can multiply it by 0.9 (or any other value 0-1) until theres less than x left from the original number.
in a loop format it would look like:
num = 4654;
mult = 0.9;
limit = 140;
count = 0;
while(num >= limit){
num *= mult;
count++;
}
But is this even possible to be done without a loop? something with logarithms?
Note that
is the inequality you wish to satisfy for some integer
k, and you seek the smallest suchk. Thenand
so that
where the inequality reverses because
log(0.9) < 0. Thus, take the smallest integerklarger thanlog(limit / num) / log(0.9).So, take the ceiling of
log(limit / num) / log(0.9).Of course, this generalizes by replacing
0.9byrwhereris your multiplier from(0, 1).