Skip to content

Instantly share code, notes, and snippets.

@mortenpi
Created August 21, 2015 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenpi/4bcf7a12c136c6493816 to your computer and use it in GitHub Desktop.
Save mortenpi/4bcf7a12c136c6493816 to your computer and use it in GitHub Desktop.
Assassin's Creed: Brotherhood audio puzzle solver
#!/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