First, neat picture! It's always cool to see the kind of emergent patterns that come out of simple rules like this.

Second, the few numbers you provided give *no* clue as to the pattern you're following. I had to puzzle thru your Python to figure it out instead. From what I can tell, the pattern is:

1. The 1st pattern, P₁, is the empty string.

2. If n is the mth prime, then Pₙ = "<" + Pₘ + ">". (So, since 2 is the 1st prime, P₂ = <>, which is P₁ wrapped in angle brackets. 3 is the 2nd prime, so it's <<>>, P₂ wrapped. 5 is P₃ wrapped, 7 is P₄ wrapped, 11 is P₅ wrapped, etc.)

3. If n is composite, it can be divided into its smallest prime factor j and the rest of the number k. Pₙ is then Pₖ+Pⱼ. (So P₄ is P₂+P₂ <><>, P₁₂ is P₄+P₃ <><><<>>, P₁₀₀ is P₅₀+P₂, etc.)

Third, your use of single-letter variables and some slightly unidiomatic Python made it a bit hard to follow. I've rewritten it here to help myself understand:

Code: Select all

`#!/usr/bin/env python2`

def generatePatterns(limit):

patterns = [""] * limit

prime = 2

primeCount = 1

while prime < limit:

# If N is the Mth prime, generate its pattern from the Mth pattern.

patterns[prime] = "<" + patterns[primeCount] + ">"

# Generate patterns for every possible multiple of prime

# from the Prime'th pattern

# and the Multiplier'th pattern

for mult in xrange(2): # we won't use the whole range

if mult*prime >= limit:

break

if patterns[multiplier]:

patterns[multiplier*newPrime] = patterns[multiplier] + patterns[newPrime]

# Now find the next prime.

# Per Eratosthene's sieve, this is just the next unfilled value.

while prime < limit and patterns[prime]:

prime += 1

primeCount += 1

return patterns

def drawPatterns(patterns):

import turtle

turtle.screensize(7000,4500)

turtle.up()

turtle.sety(-200)

turtle.down()

for pattern in patterns:

for command in pattern:

if command == ">":

turtle.right(60)

turtle.forward(5)

else:

turtle.left(30)

turtle.forward(5)

print(pattern,i)

drawPatterns(generatePatterns(10**6))

I haven't run this, but I think it works? Is this code clear to you?