Skip to content

Home

Geometric progression

Initializes a list containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step.

from math import floor, log

def geometric_progression(end, start=1, step=2):
  return [start * step ** i for i in range(floor(log(end / start)
          / log(step)) + 1)]

geometric_progression(256) # [1, 2, 4, 8, 16, 32, 64, 128, 256]
geometric_progression(256, 3) # [3, 6, 12, 24, 48, 96, 192]
geometric_progression(256, 1, 4) # [1, 4, 16, 64, 256]

More like this

Start typing a keyphrase to see matching snippets.