Skip to main content
The National Cipher Challenge

Reply To: Programming

A Tale of 2 Secrets Forums T.E.M.P.E.S.T. Programming Reply To: Programming

#109850
upsidedown
Participant

Re @ByteInBits #107489

Here’s my solution based on intersections of sets of multiples of 3, 4 & 7 (like a Venn diagram).


# python
from functools import reduce

def gcd(a, b): return a if b == 0 else gcd(b, a % b)
def lcm(a, b): return a * b // gcd(a, b)
def multiples(D, n): return n // reduce(lcm, D)

n = 100
m = lambda D: multiples(D, n)

a, b, c = 3, 4, 7

sum1 = m({a}) + m({b}) + m({c})
sum2 = m({a, b}) + m({b, c}) + m({c, a})
sum3 = m({a, b, c})

total_div = sum1 - sum2 + sum3
total_not_div = n - total_div

print(f'{total_not_div / n:.0%}')

42%

Report a problem