Skip to content

Instantly share code, notes, and snippets.

@NeilNjae
Created September 25, 2018 15:10
Show Gist options
  • Save NeilNjae/ed49f4c9f34cd1e44a6001647405a0ff to your computer and use it in GitHub Desktop.
Save NeilNjae/ed49f4c9f34cd1e44a6001647405a0ff to your computer and use it in GitHub Desktop.
# Solution to Lucy's secret number puzzle, from
# http://datagenetics.com/blog/june12018/index.html
import collections
# how are the four questions answered for this number?
def signature(n):
return ( n % 2 == 0
, n % 3 == 0
, n % 5 == 0
, n % 7 == 0
)
# For each "signature", what numbers share that signature?
signatures = collections.defaultdict(list)
for i in range(1, 100):
signatures[signature(i)] += [i]
# What signatures have just one number each?
[(k, v) for k, v in signatures.items() if len(v) == 1]
# -> [((False, False, True, True), [35]), ((True, False, True, True), [70])]
# The solution is obvious by inspection: if you heard the first question and answer,
# you know the number. If the answer was "Yes" (i.e. True), the number is 70.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment