Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- N = 200
- def is_prime(n):
- i=2
- if n<i:
- return False
- for x in range(i, n):
- if n%x==0:
- return False
- return True
- prime_numbers = []
- for i in range(1,N):
- prime = is_prime_alternative(i)
- if prime:
- prime_numbers.append(i)
- def lowest_divisor(x):
- if x < 2:
- print("Error. Number too small.")
- if x in [2,3,4,5]:
- return [2,3,2,5][x-2]
- lowest_divisor = 1
- for i in range(2,x//2):
- if x%i == 0:
- lowest_divisor = i
- return lowest_divisor
- if i == x//2-1:
- return x
- ratiolist = []
- for i in range(2,N):
- ratio = float(i)/float(lowest_divisor(i))
- ratiolist.append(ratio)
- x = np.arange(2,N,1)
- # x and y ("ratiolist") without the prime numbers:
- x_filtered = [value for value in x if not is_prime(value)]
- ratiolist_filtered = []
- for i in range(2,N):
- if not is_prime(i):
- ratio = float(i)/float(lowest_divisor(i))
- ratiolist_filtered.append(ratio)
- lowest_divisor_list = []
- for i in range(2,N):
- if not is_prime(i):
- lowest_divisor_list.append(lowest_divisor(i))
- # plot
- fig0, ax0 = plt.subplots(figsize=(15,5))
- ax0.scatter(x_filtered,lowest_divisor_list)
- ax0.set_title('The lowest divisor.')
- plt.ylabel("lowest divisor for x", fontsize=12)
- fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15,5))
- ax1.scatter(x, ratiolist)
- ax1.set_title('With prime numbers')
- ax1.set_ylabel("ratio of x to its lowest divisor", fontsize=12)
- ax2.scatter(x_filtered, ratiolist_filtered)
- ax2.set_title('Without prime numbers')
- ax2.set_ylabel("ratio of x to its lowest divisor", fontsize=12)
- # ignore this code snippet, it's from another project:
- def intersection(l1, l2):
- l3 = [value for value in l1 if value in l2]
- return l3
- def overhang(l1, l2):
- l3 = [value for value in l1 if value not in intersection(l1,l2)]
- return l3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement