-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
36 lines (31 loc) · 983 Bytes
/
Copy pathsolution.py
File metadata and controls
36 lines (31 loc) · 983 Bytes
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
import json
import time
import numpy as np
from functools import lru_cache
from typing import List
from multiprocessing import Pool
def get_primes(up_to: int) -> List[int]:
primes = list(range(up_to + 1))
primes[0], primes[1] = 0, 0
for i in primes:
if not i:
continue
for j in range(2, up_to//i + 1):
primes[i*j] = 0
primes = list(set(primes))
primes.remove(0)
return sorted(primes)
_PRIMES = get_primes(1000)
def solution() -> int:
# We are essentially just looking for a number smaller or equal to
# 1000000 with most prime factors
result = 1
for p in _PRIMES:
if result * p > 1000000:
return result
result = result * p
cpu_s, wall_s = time.process_time(), time.time()
result = solution()
cpu_e, wall_e = time.process_time(), time.time()
cpu_time, wall_time = cpu_e - cpu_s, wall_e - wall_s
print(json.dumps({"solution": result, "cpu": cpu_time, "wall": wall_time}))