Last active
February 2, 2018 01:48
-
-
Save shiracamus/6e7f3db3a02518769171e9217cd244f4 to your computer and use it in GitHub Desktop.
オフラインリアルタイムどう書く F09 のPython実装例 https://qiita.com/Nabetani/items/61e13fa5cf0abe5979be
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 | |
# -*- coding:utf-8 -*- | |
position = lambda name: { | |
'a':(1, 2, 3), 'd':(7, 4, 1), 'g':(9, 8, 7), 'j':(3, 6, 9), | |
'b':(4, 5, 6), 'e':(8, 5, 2), 'h':(6, 5, 4), 'k':(2, 5, 8), | |
'c':(7, 8, 9), 'f':(9, 6, 3), 'i':(3, 2, 1), 'l':(1, 4, 7), | |
}[name] | |
def solve(data): | |
numbers = list('0123456789') | |
for a, b, c in map(position, data): | |
numbers[a], numbers[b], numbers[c] = numbers[b], numbers[c], numbers[a] | |
return ''.join(numbers[1:4] + ['/'] + numbers[4:7] + ['/'] + numbers[7:10]) | |
def test(data, expect): | |
answer = solve(data) | |
print(("NG", "OK")[answer == expect], data, expect, answer) | |
test( "aegj", "286/435/971" ); | |
test( "a", "231/456/789" ); | |
test( "e", "183/426/759" ); | |
test( "g", "123/456/978" ); | |
test( "j", "126/459/783" ); | |
test( "bb", "123/645/789" ); | |
test( "jjj", "123/456/789" ); | |
test( "bd", "723/164/589" ); | |
test( "ah", "231/645/789" ); | |
test( "bj", "124/569/783" ); | |
test( "db", "723/561/489" ); | |
test( "dh", "723/615/489" ); | |
test( "dl", "123/456/789" ); | |
test( "hc", "123/645/897" ); | |
test( "gf", "128/453/976" ); | |
test( "hl", "623/745/189" ); | |
test( "ja", "261/459/783" ); | |
test( "ld", "123/456/789" ); | |
test( "ki", "315/486/729" ); | |
test( "lfa", "294/753/186" ); | |
test( "kga", "531/486/972" ); | |
test( "dbi", "372/561/489" ); | |
test( "che", "193/625/847" ); | |
test( "iea", "823/416/759" ); | |
test( "gbl", "523/964/178" ); | |
test( "egj", "186/425/973" ); | |
test( "jcf", "127/456/839" ); | |
test( "djh", "726/915/483" ); | |
test( "hld", "123/645/789" ); | |
test( "leeh", "453/678/129" ); | |
test( "heja", "851/629/743" ); | |
test( "cakh", "251/649/837" ); | |
test( "bhjik", "652/489/713" ); | |
test( "eabji", "483/269/751" ); | |
test( "cdbch", "823/156/974" ); | |
test( "ckgajc", "536/492/817" ); | |
test( "ggchha", "231/564/978" ); | |
test( "gfbkeg", "128/534/697" ); | |
test( "agfbcbf", "239/148/765" ); | |
test( "ekahijf", "123/645/789" ); | |
test( "hajdjbe", "789/432/615" ); | |
test( "elgililj", "976/325/814" ); | |
test( "chffefif", "317/629/845" ); | |
test( "ilbbihak", "462/587/319" ); | |
test( "abcdefghijkl", "123/456/789" ); | |
test( "hkijbglfaced", "768/125/493" ); | |
test( "dfkbjiechlga", "256/387/419" ); | |
test( "hgfkbidlajce", "186/745/239" ); | |
test( "baciefjhgkdl", "153/482/796" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment