Skip to content

Instantly share code, notes, and snippets.

View norvig's full-sized avatar

Peter Norvig norvig

View GitHub Profile
@norvig
norvig / minsumprimeset.py
Last active June 9, 2021 19:57
Use each of the digits 1-9 exactly twice to form a set of distinct prime numbers with the smallest possible sum.
from collections import Counter, namedtuple
def is_prime(i) -> bool: return all(i % p for p in range(2, i))
def primes(N): return [p for p in range(2, N) if is_prime(p)]
# Set: `ints` are a set of integers that total to `sum`;
# `need` is a Counter of digits that are needed to complete the Set.
Set = namedtuple('Set', 'ints, sum, need')