Problem 58 and update gitignore

This commit is contained in:
kevindkeogh
2018-07-02 19:29:17 -04:00
parent fd43cd0e0d
commit 8ab046ea6f
2 changed files with 27 additions and 0 deletions

26
problem-58.py Normal file
View File

@@ -0,0 +1,26 @@
from primes import is_prime
diags = [1]
nums = [1]
spiral = 1
primes = []
if __name__ == '__main__':
while True:
spiral += 2
circ = list(range(diags[-1] + 1, spiral**2+1))
stride = int(len(circ) / 4)
corners = [circ[stride*1-1],
circ[stride*2-1],
circ[stride*3-1],
circ[stride*4-1]
]
diags.extend(corners)
primes.extend([num for num in corners if is_prime(num)])
if len(primes) / len(diags) < 0.1:
break
print(len(primes), len(diags), spiral)