Created
December 3, 2012 04:14
-
-
Save matiskay/4192665 to your computer and use it in GitHub Desktop.
Get the minimum integer value from an operation combining a set of integer.
This file contains hidden or 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
numbers = [5, 7, 8, 6, 4] | |
values = [] | |
#5 6 7 4 8 | |
#6 5 7 4 8 | |
def is_integer(n, p, q, r, s): | |
if ((n + p - q) * r) % s == 0: | |
return True | |
def calculate(n, p, q, r, s): | |
if ((n + p - q) * r) % s == 0: | |
return ((n + p - q) * r) / s | |
for n in numbers: | |
for p in numbers: | |
if p in [n]: | |
continue | |
for q in numbers: | |
if q in [n, p]: | |
continue | |
for r in numbers: | |
if r in [n, p, q]: | |
continue | |
for s in numbers: | |
if s in [n, p, q, r]: | |
continue | |
if is_integer(n, p, q, r, s): | |
values.append(calculate(n, p, q, r, s)) | |
if calculate(n, p, q, r, s) == 2: | |
print n, p, q, r, s | |
print values | |
print min(values) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment