≡ Menu

Define a Prime Number function generator

import matplotlib.pyplot as plt
import time


def timer(func):
    def wrapper(*args, **kwargs):
        before = time.time()
        result = func(*args, **kwargs)
        print('Function took:', time.time() - before, " seconds")
        return result
    return wrapper


@timer
def pattern_1(end_value):
    
    start = 1
    xs = []
    ys = []
    for val in range(start, end_value + 1): 
        if val > 1:
            for n in range(2, val): 
                if (val % n) == 0: 
                       break
            else:
                xs.append(val)
                ys.append(val)



    fig = plt.figure(figsize=(15, 15))
    plt.polar(xs, ys, 'g.')
    ax = plt.gca()



pattern_1(100)
plt.show()

Run program for 100 iterations

Run program for 1000 iterations

Run program for 10000 iterations

Run program for 100000 iterations

Run program for 1000000 iterations

{ 0 comments… add one }

Rispondi