Created
August 21, 2015 19:52
-
-
Save mortenpi/4bcf7a12c136c6493816 to your computer and use it in GitHub Desktop.
Assassin's Creed: Brotherhood audio puzzle solver
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
#!/usr/bin/env python3 | |
import itertools | |
def powerset(iterable): | |
xs = list(iterable) | |
return itertools.chain.from_iterable( | |
itertools.combinations(xs,n) for n in range(len(xs)+1) | |
) | |
samples = [ | |
[4, -2, 1, -4], [4, -2, 3, -1], [3,2,1,-3], | |
[-3, 1, -2, 0], [0, -2, 1, -3], [4,1,-3,2], | |
[1, -2, 1, -3], [-1, 1, -4, 1], [-2,0,4,2] | |
] | |
solution = [1, -3, 2, -4] | |
def add(keys): | |
sum = [0,0,0,0] | |
for k in keys: | |
sum[0] += samples[k][0] | |
sum[1] += samples[k][1] | |
sum[2] += samples[k][2] | |
sum[3] += samples[k][3] | |
return sum | |
for sks in powerset(range(len(samples))): | |
s = add(sks) | |
print('{} -> {}'.format(sks, s)) | |
if s == solution: | |
print('Solution found!') | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment