diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-10-20 11:27:47 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-10-20 11:27:47 +0700 |
commit | 4c5ed94087a691ce47882786aea64f7b5bf3c130 (patch) | |
tree | 6ebb9374e9c9e1d867659a1de166fbe8f6481b19 /codechef/chefprms.py | |
parent | 662168dbd56cbeba35bea782d580b0f7cc9a3ac2 (diff) | |
download | cp-4c5ed94087a691ce47882786aea64f7b5bf3c130.tar.gz |
Bon appétit
Diffstat (limited to 'codechef/chefprms.py')
-rwxr-xr-x | codechef/chefprms.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/codechef/chefprms.py b/codechef/chefprms.py new file mode 100755 index 0000000..355606b --- /dev/null +++ b/codechef/chefprms.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +from itertools import combinations, combinations_with_replacement +from operator import add, mul + + +def prime(n): + """Check if n is a prime using trial division.""" + for i in range(2, n): + if not n%i: return False + return True + + +def up200(n): return n <= 200 +def apply(f): return lambda x: f(*x) + + +primes = filter(prime, range(2, 200)) +semis = set(filter(up200, map(apply(mul), combinations(primes, 2)))) +chefprms = filter(up200, map(apply(add), + combinations_with_replacement(semis, 2))) +print(len(set(chefprms))) |