title: How to calculate a percentage as an exponential progression?
body: <p>What I want to do is very simple, but I can't figure out the math and code for it.</p>
  
  <p>I have a percentage that I display in the console as a new number with each progressive step. So I know the exact percentage 1-100 each step. Assuming a constant progression, what I want is to only show the numbers that are on an some exponential function:</p>
  
  <p>Instead of showing: </p>
  
  <blockquote>
    <p>1,2,3,4,5,6,7....100</p>
  </blockquote>
  
  <p>I want show only:   </p>
  
  <blockquote>
    <p>1,2,4,8,15,25,40,65,90,(100)</p>
  </blockquote>
  
  <p>Or something like that. The idea is to show initial activity, but slow down on the percentage spamming soon after.</p>
  
  <p>How can I do this? The only thing I can think of is to define a fixed array of numbers that are allowed to be printed (perhaps that is the best solution? I feel there should be a more elegant math based solution, though). Hmm, or perhaps fill such an array using an exponential function / easing curve.</p>
  
  <p>Adding some information on how the percentage is acquired:</p>
  
  <pre class="lang-java prettyprint-override"><code>for (int i = 0; i &lt; batchjob.size(); i++) {
     int percent = 100 * i / batchjob.size();
     log.debug("Progress: {}/{} = {}%", i, batchjob.size(), percent));
  }
  </code></pre>
  
  <p>Now I tried the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>final Set&lt;Integer&gt; progressDisplay = newHashSet(1, 2, 4, 8, 15, 25, 40, 65, 90, 100);
  
  for (int i = 0; i &lt; batchjob.size(); i++) {
     int percent = 100 * i / batchjob.size();
     if (progressDisplay.contains(percent)) {
          log.debug("Progress: {}/{} = {}%", i, batchjob.size(), percent));
     }
  }
  </code></pre>
  
  <p>However, this results in something like:</p>
  
  <blockquote>
    <p>1,1,1,1,1,1,1,2,2,2,2,2,2,2,4,4,4,4,4,4,4,8,8,8,8,8,8,8...etc</p>
  </blockquote>
  
  <hr>
  
  <h1>Solution</h1>
  
  <p>I went with a combination of the accepted answer and a fixed array. I finally decided on a simple array as I can tweak the numbers more easily.</p>
  
  <pre class="lang-java prettyprint-override"><code>final int[] progressDisplay = {1, 3, 8, 20, 50, 75, 100};
  int lastMatchingIndex = 0;
  
  for (int i = 0; i &lt; batchjob.size(); i++) {
      processBatchJob(batchjob.get(i));
      int percent = 100 * i / batchjob.size();
      if (progressDisplay[lastMatchingIndex] == percent) {
          log.debug("Progress: {}/{} = {}%", i, batchjob.size(), percent);
          lastMatchingIndex++;
      }
  }
  </code></pre>