Last active
August 29, 2015 14:17
-
-
Save mheistermann/e23f80063de9fba98a64 to your computer and use it in GitHub Desktop.
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 python | |
# encoding: utf-8 | |
# try to find a solution to a subproblem of the Archer ARG | |
# Author: Martin Heistermann <code()mheistermann.de> | |
# License: THE BEER-WARE LICENSE (Revision 42): | |
# Martin Heistermann wrote this software. As long as you retain this notice | |
# you can do whatever you want with this stuff. If we meet some day, and you | |
# think this stuff is worth it, you can buy me a beer in return. | |
solutions = [ | |
'IOPLINETUOWEAUZGORFFCKGNUBOMEUOAZXSWVGKMUKVO', | |
'IOLPINEUOTWAEUZGORCFGBUOMFKENOZAXSUVGKMWKVUO'] | |
fill_grids = [[ | |
0,5,10,15, 20,24,29,34,39, | |
1,6,11,16, 21,25,30,35,40, | |
2,7,12,17,None,26,31,36,41, | |
3,8,13,18, 22,27,32,37,42, | |
4,9,14,19, 23,28,33,38,43], | |
range(22) + [None] + range(22,44), | |
] | |
s1_grids = [ | |
[ | |
0, 1, 2, 3,None,None,None,None,None, | |
4, 5, 6, 7,None,None,None,None,None, | |
8, 9,10,11,None,None,None,None,None, | |
12,13,14,15, 16,None,None,None,None, | |
17,18,19,20, 21,None,None,None,None], | |
[ | |
0,5,10,15, None,None,None,None,None, | |
1,6,11,16, None,None,None,None,None, | |
2,7,12,17, None,None,None,None,None, | |
3,8,13,18, 20,None,None,None,None, | |
4,9,14,19, 21,None,None,None,None], | |
] | |
s2_grids = [ | |
[ | |
None, None, None, None, 0, 1, 2, 3, 4, | |
None, None, None, None, 5, 6, 7, 8, 9, | |
None, None, None, None, None,10,11,12,13, | |
None, None, None, None, None,14,15,16,17, | |
None, None, None, None, None,18,19,20,21], | |
[ | |
None, None, None, None, 4, 3, 2, 1, 0, | |
None, None, None, None, 9, 8, 7, 6, 5, | |
None, None, None, None, None,13,12,11,10, | |
None, None, None, None, None,17,16,15,14, | |
None, None, None, None, None,21,20,19,18], | |
[ | |
None, None, None, None, 21,20,19,18,17, | |
None, None, None, None, 16,15,14,13,12, | |
None, None, None, None, None, 11,10, 9, 8, | |
None, None, None, None, None, 7, 6, 5, 4, | |
None, None, None, None, None, 3, 2, 1, 0], | |
[ | |
None, None, None, None, 21,19,14, 9, 4, | |
None, None, None, None, 20,18,13, 8, 3, | |
None, None, None, None, None, 17,12, 7, 2, | |
None, None, None, None, None, 16,11, 6, 1, | |
None, None, None, None, None, 15,10, 5, 0], | |
[ | |
None, None, None, None, 20,15,10, 5, 0, | |
None, None, None, None, 21,16,11, 6, 1, | |
None, None, None, None, None, 17,12, 7, 2, | |
None, None, None, None, None, 18,13, 8, 3, | |
None, None, None, None, None, 19,14, 9, 4], | |
] | |
def print_grid(grid): | |
stride = 9 | |
for k in range(0, len(grid), stride): | |
row = grid[k:k+stride] | |
print " ".join(x or " " for x in row) | |
def splitsol(s, fill_grid, s1_grid, s2_grid): | |
grid = [None]*45 | |
s1 = [None]*22 | |
s2 = [None]*22 | |
for dest, src in enumerate(fill_grid): | |
if src is not None: | |
grid[dest] = s[src] | |
for src, dest in enumerate(s1_grid): | |
if dest is not None: | |
s1[dest] = grid[src] | |
for src, dest in enumerate(s2_grid): | |
if dest is not None: | |
s2[dest] = grid[src] | |
#print_grid(grid) | |
s1 = "".join(s1) | |
s2 = "".join(s2) | |
return s1, s2 | |
import string | |
import operator | |
def add_strings(s1, s2, charset=string.uppercase, op=operator.add): | |
def add_letters(a, b): | |
ai = charset.index(a) | |
bi = charset.index(b) | |
return charset[op(ai,bi) % len(charset)] | |
return "".join((add_letters(a,b) for (a,b) in zip(s1, s2))) | |
def main(): | |
for s in solutions: | |
for fill_grid in fill_grids: | |
for s1_grid in s1_grids: | |
for s2_grid in s2_grids: | |
s1, s2 = splitsol(s, fill_grid, s1_grid, s2_grid) | |
for op in [operator.add, operator.sub, lambda a,b: b-a]: | |
#print "%s + %s = %s" % (s1, s2, add_strings(s1,s2)) | |
print add_strings(s1,s2, op=op) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment