Skip to content

Instantly share code, notes, and snippets.

@paniq
Created March 6, 2019 08:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paniq/0f96fdc56ee22a742b373364fc13d4c9 to your computer and use it in GitHub Desktop.
Save paniq/0f96fdc56ee22a742b373364fc13d4c9 to your computer and use it in GitHub Desktop.
# Polyrhythmic Prime Discovery
# by Leonard Ritter <contact@leonard-ritter.com>
primes = []
phases = []
counter = 2
def is_any_phase_zero ():
for phase in phases:
if phase == 0:
return True
return False
def advance_phases ():
i = 0
primecount = len(primes)
while (i < primecount):
# increase each phase in the modspace of its prime
# we're explicitly not using % here to show
# how simple this mechanism is.
x = phases[i]
x += 1
if x == primes[i]:
x = 0
phases[i] = x
i = i + 1
while True:
if not is_any_phase_zero():
# no phase is zero, we are off-beat
# therefore, we found a new prime
# print it
print counter
# and append to list of rhythms to track
primes.append(counter)
phases.append(0)
advance_phases()
counter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment