Last active
August 29, 2015 14:01
-
-
Save shayelkin/2397850f9b2c3df7e3aa to your computer and use it in GitHub Desktop.
What is the smallest natural number that can not be generated using the numbers 1,2,3,4 (exactly once each) and four basic arithmetic operations?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
from sys import maxint | |
from itertools import permutations, product | |
ops = [operator.add, operator.sub, operator.mul, operator.div] | |
possibilities = set(reduce(lambda v, t: t[0](v,t[1]), zip(o, n[1:]), n[0]) for n in permutations(range(1,5)) for o in product(ops, repeat=3)) | |
# Without repeating operators: | |
# possibilities = set(reduce(lambda v, t: t[0](v,t[1]), zip(o, n[1:]), n[0]) for n in permutations(range(1,5)) for o in permutations(ops, repeat=3)) | |
next(x for x in xrange(maxint) if x not in possibilities) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment