GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — project_euler/euler12.py at main · Babissimo/project_euler

Expand file tree

/

euler12.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
46 lines (38 loc) · 1.08 KB
/

euler12.py

Copy path

File metadata and controls

46 lines (38 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 1st triangle number with 500+ divisors
import math
num_of_divisors = {
1 : 1,
2 : 2,
3 : 2,
6 : 4,
10 : 4,
15 : 4,
21 : 4,
28 : 6,
}
def countDivisorsTriangle(t, n):
if n%2 == 0:
num_of_divisors[n/2] = num_of_divisors.get(n/2, countDivisors(n/2))
num_of_divisors[n+1] = num_of_divisors.get(n+1, countDivisors(n+1))
return num_of_divisors[n/2] * num_of_divisors[n+1]
else:
num_of_divisors[n] = num_of_divisors.get(n, countDivisors(n))
num_of_divisors[(n+1)/2] = num_of_divisors.get((n+1)/2, countDivisors((n+1)/2))
return num_of_divisors[n] * num_of_divisors[(n+1)/2]
def countDivisors(n):
# count in pairs up to sqrt
divisorCount = 2
for i in range(2, int(math.sqrt(n))):
partnerDivisor = n/i
if int(partnerDivisor)==partnerDivisor:
divisorCount += 2
return divisorCount
nth = 7
tri = 28
found = False
while not found:
nth += 1
tri += nth
num_of_divisors[tri] = countDivisorsTriangle(tri, nth)
found = num_of_divisors[tri] >= 500
print(tri)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.