Skip to content

Instantly share code, notes, and snippets.

@airtoxin
Created December 13, 2013 04:31
Show Gist options
  • Save airtoxin/7939791 to your computer and use it in GitHub Desktop.
Save airtoxin/7939791 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
u"""
mymodule.stablesortは https://github.com/airtoxin/mymodule/blob/master/stablesort.py
"""
from numpy import array
from mymodule.stablesort import stable_sort_by_row, stable_sort_by_column
default_array = array([[4, 1, 4, 2, 1, 3],
[7, 3, 2, 0, 5, 0],
[2, 3, 6, 0, 6, 7],
[6, 4, 5, 7, 5, 1],
[3, 1, 6, 6, 2, 4],
[6, 0, 5, 5, 5, 1]])
row_index_dict = {w: i for w, i in zip("ABCDEF", range(6))}
col_index_dict = {w: i for w, i in zip("uvwxyz", range(6))}
def solve(input_string):
arr = default_array[:]
for s in input_string:
if s in row_index_dict:
s_index = row_index_dict[s]
arr = stable_sort_by_row(arr, s_index)
else:
s_index = col_index_dict[s]
arr = stable_sort_by_column(arr, s_index)
return "".join(str(i)for i in arr[0])
def test(input_string, output_string):
ans = solve(input_string)
print "OK" if ans == output_string else "NG", ans, output_string, input_string
if __name__ == "__main__":
test("AvEx", "305027")
test("A", "112344")
test("C", "241413")
test("F", "134214")
test("u", "236067")
test("w", "732050")
test("y", "414213")
test("yx", "732050")
test("ux", "236067")
test("EF", "131424")
test("DF", "134124")
test("Au", "055165")
test("uA", "023667")
test("By", "234114")
test("yB", "114342")
test("yBy", "357020")
test("yByB", "350072")
test("AuBvCw", "131244")
test("FAuFBvFCw", "300527")
test("AuBv", "112344")
test("CwDx", "515056")
test("FzyE", "324114")
test("uAwDyB", "114324")
test("zExCvF", "073520")
test("uFxEv", "002357")
test("DyCwB", "076362")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment