[PYTHON] Antwort auf "Offline-Echtzeit, wie man ein F01-Problem schreibt"

http://nabetani.sakura.ne.jp/hena/ordf01_twicel/ Antworten 1 Stunde und 30 Minuten .... Es gibt noch mehr.

main.py


MAX_CEL_COUNT = 8

def get_bit(data, x, y):
    if x<0 or y<0 or x>=MAX_CEL_COUNT or y>=MAX_CEL_COUNT:
        return -1
    return data[x][y]


def twicel_smell(data, cx, cy):
    current_bit = get_bit(data, cx, cy)
    hitcel = (-1, -1)
    hitcount = 0

    arounds = [[0, -1],[0, 1],[-1, 0],[1, 0]]

    for around in arounds:
        if current_bit == get_bit(data, cx + around[0], cy + around[1]):
            hitcount +=1
            hitcel = (cx + around[0], cy + around[1])

    if hitcount != 1:
        return None

    return hitcel

def count_twicel(cels):
    targets = []
    data = [[]]
    hitresult = [0,0]
    for i in range(0, MAX_CEL_COUNT):
        raw = format(cels[i], '08b')
        data.append([])
        for j in range(0, MAX_CEL_COUNT):
            targets.append((i, j))
            data[i].append(int(raw[j]))


    for target in targets:
        result1 = twicel_smell(data, target[0], target[1])
        if result1 == None:
            continue
        result2 = twicel_smell(data, result1[0], result1[1])
        if target == result2:
            hitresult[get_bit(data, target[0], target[1])] += 1
            targets.remove(result1)

    return (hitresult[0], hitresult[1])


def test(result, actual, expect):
    result[0 if actual == expect else 1] +=1

result= [0,0]
test(result, count_twicel([0xdc, 0xbc, 0xa7, 0x59, 0x03, 0xd5, 0xd4, 0xea]), (2,3))
test(result, count_twicel([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]), (0,0))
test(result, count_twicel([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), (0,0))
test(result, count_twicel([0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33]), (16,16))
test(result, count_twicel([0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55]), (16,16))
test(result, count_twicel([0xac, 0xa3, 0x5c, 0x53, 0xca, 0x3a, 0xc5, 0x35]), (8,8))
test(result, count_twicel([0xdb, 0x00, 0xdb, 0x00, 0xdb, 0x00, 0xaa, 0xaa]), (0,13))
test(result, count_twicel([0x24, 0x24, 0xdb, 0x24, 0x24, 0xdb, 0x24, 0x24]), (0,12))
test(result, count_twicel([0xd7, 0xd7, 0xe9, 0xf1, 0xf7, 0xde, 0x60, 0x56]), (3,2))
test(result, count_twicel([0x17, 0x7d, 0x64, 0x9b, 0xa5, 0x39, 0x53, 0xa6]), (2,2))
test(result, count_twicel([0xbb, 0x8f, 0x18, 0xfb, 0x89, 0xc2, 0xc7, 0x35]), (1,2))
test(result, count_twicel([0x6d, 0x63, 0x20, 0x08, 0x54, 0xcd, 0x32, 0x4f]), (2,2))
test(result, count_twicel([0xa9, 0xca, 0xcd, 0x46, 0x99, 0xe6, 0xf0, 0x30]), (2,2))
test(result, count_twicel([0x5b, 0x70, 0xfd, 0x45, 0xe2, 0xa1, 0xab, 0x9a]), (1,2))
test(result, count_twicel([0x24, 0xe4, 0xa8, 0x12, 0xe1, 0xa6, 0x3f, 0xf3]), (2,1))
test(result, count_twicel([0x79, 0x32, 0x2e, 0x07, 0xd5, 0x10, 0xe7, 0x9d]), (2,2))
test(result, count_twicel([0x60, 0xbc, 0xab, 0xec, 0x1f, 0xeb, 0x63, 0x2c]), (4,2))
test(result, count_twicel([0xa5, 0xdd, 0x92, 0x4e, 0x67, 0xc6, 0xdc, 0x34]), (6,1))
test(result, count_twicel([0xaa, 0x96, 0x6d, 0x67, 0xd2, 0xa8, 0xac, 0x90]), (3,2))
test(result, count_twicel([0x95, 0x72, 0x7d, 0x5c, 0x47, 0xdc, 0xef, 0x99]), (4,0))
test(result, count_twicel([0x17, 0xd6, 0x6a, 0x27, 0x1f, 0x25, 0x26, 0xb8]), (2,1))
test(result, count_twicel([0xf0, 0xf3, 0x76, 0xc5, 0x31, 0xca, 0x6b, 0xae]), (1,2))
test(result, count_twicel([0x01, 0x59, 0x26, 0xfa, 0x8c, 0x70, 0x12, 0xcd]), (1,4))
test(result, count_twicel([0x1a, 0xc3, 0x1f, 0x0b, 0x83, 0xb6, 0x81, 0x0d]), (0,5))
test(result, count_twicel([0x4c, 0x49, 0x05, 0xcf, 0x54, 0xbb, 0x1f, 0xda]), (1,2))
test(result, count_twicel([0xeb, 0x7c, 0xd5, 0x09, 0x2a, 0xc2, 0x14, 0x6b]), (0,7))
test(result, count_twicel([0xb4, 0xd3, 0x4c, 0xc4, 0xed, 0x19, 0xe8, 0x63]), (1,3))
test(result, count_twicel([0xbd, 0xbc, 0x6d, 0x60, 0x9b, 0x00, 0x9a, 0x32]), (2,4))
test(result, count_twicel([0x94, 0x97, 0x3f, 0xe3, 0xc7, 0x06, 0x15, 0xc0]), (2,2))
test(result, count_twicel([0x5f, 0x1d, 0x67, 0x16, 0xb8, 0xf7, 0x0a, 0x2a]), (2,2))
test(result, count_twicel([0xdf, 0xe6, 0xf9, 0x4f, 0x59, 0xe9, 0x1f, 0xee]), (3,0))
test(result, count_twicel([0x5a, 0x53, 0x9a, 0x9a, 0x73, 0xb4, 0x37, 0x07]), (3,2))
test(result, count_twicel([0xbd, 0x87, 0x7c, 0xe7, 0xc0, 0x37, 0x82, 0xda]), (2,3))
test(result, count_twicel([0x3d, 0xc0, 0x13, 0xac, 0x57, 0x3d, 0x15, 0x78]), (2,2))
test(result, count_twicel([0x63, 0x64, 0x54, 0x3a, 0x40, 0x28, 0x4e, 0x4e]), (0,3))
test(result, count_twicel([0xf6, 0x81, 0xc9, 0x15, 0x00, 0x4c, 0xa0, 0xa8]), (1,4))
test(result, count_twicel([0x19, 0x41, 0xdf, 0xf8, 0xe3, 0x74, 0x6b, 0x9b]), (4,2))
test(result, count_twicel([0xd5, 0x0b, 0xdd, 0x35, 0x3b, 0xd2, 0x0b, 0x6b]), (1,5))
test(result, count_twicel([0x08, 0xb7, 0x91, 0xf3, 0x6e, 0x3c, 0x74, 0xa0]), (0,0))
test(result, count_twicel([0xb8, 0xa8, 0xb4, 0xa6, 0x93, 0x2c, 0x94, 0x3f]), (0,0))
test(result, count_twicel([0x88, 0x22, 0x21, 0xee, 0xdc, 0x19, 0x43, 0x01]), (0,0))
test(result, count_twicel([0xe1, 0xee, 0x35, 0xbc, 0xfc, 0x00, 0x8e, 0xfe]), (0,0))
test(result, count_twicel([0x3c, 0x42, 0x63, 0x5f, 0x27, 0x47, 0x07, 0x90]), (0,0))

print("Success:" + str(result[0]) + ", Fail:" + str(result[1]))

Änderung am 26.01.2017

Ich habe den Code ein wenig gekürzt.

Recommended Posts

Antwort auf "Offline in Echtzeit, wie man ein F02-Problem schreibt"
Antwort auf "Offline-Echtzeit, wie man ein F01-Problem schreibt"
Antwort auf "Offline-Echtzeit, wie man ein E13-Problem schreibt"
Antwort auf "Offline in Echtzeit, wie man ein F04-Problem schreibt"
Antwort auf "Offline in Echtzeit, wie man ein F05-Problem schreibt"
Antwort auf "Offline in Echtzeit, wie man ein E12-Problem schreibt"
Das 15. Offline-Echtzeit-Schreiben eines Referenzproblems in Python
Offline-Echtzeit zum Schreiben eines Python-Implementierungsbeispiels für das E15-Problem
Das 14. Referenzproblem beim Schreiben in Echtzeit in Python
Das 18. Offline-Echtzeit-Schreiben eines Referenzproblems in Python
Das 16. Offline-Echtzeit-Schreibproblem wurde mit Python gelöst
17. In Python implementiertes Referenzproblem für das Offline-Schreiben in Echtzeit
Das 19. Offline-Echtzeit-Schreiben eines Referenzproblems zur Lösung mit Python
Das 15. Offline-Problem beim Schreiben in Echtzeit wurde mit Python gelöst
20. Offline-Echtzeit So schreiben Sie Probleme in Python
So schreiben Sie offline in Echtzeit Lösen von E05-Problemen mit Python
Beim 15. Offline-Echtzeitversuch habe ich versucht, das Problem des Schreibens mit Python zu lösen
Offline in Echtzeit, wie man ein Implementierungsbeispiel für E11 Ruby und Python schreibt
So schreiben Sie offline in Echtzeit Lösen von F01-Problemen mit Python
Ich habe versucht, das Problem von F02 zu lösen, wie man mit Python offline in Echtzeit schreibt
Teil 1 Ich habe die Antwort auf das Referenzproblem geschrieben, wie man in Python in Echtzeit offline schreibt
XPath-Grundlagen (2) - So schreiben Sie XPath
Teil 1 Ich habe ein Beispiel für die Antwort auf das Referenzproblem geschrieben, wie man in Python in Echtzeit offline schreibt
13. Offline-Echtzeit So lösen Sie Schreibprobleme mit Python
Wie man nüchtern mit Pandas schreibt
Wiederverwendung von Flaschen Wie schreibe ich HTML?
So schreiben Sie ein Docker-Basis-Image
Wie schreibe ich Django1.9 umweltunabhängig wsgi.py
Hinweise zum Schreiben von require.txt
17. Offline-Echtzeit So lösen Sie Schreibprobleme mit Python
So schreiben Sie offline in Echtzeit Lösen von E04-Problemen mit Python
Antwort auf das Problem der Überbeanspruchung des Splash-Speichers (Entwurf)
Qiita (1) Wie schreibe ich einen Codenamen?
Wie man optuna einstellt (wie man einen Suchraum schreibt)
So schreiben Sie Python-Dokumentkommentare (Docstrings)
Wie man offline in Echtzeit schreibt Ich habe versucht, E11 mit Python zu lösen
Wie schreibe ich diesen Prozess in Perl?
Wie man Problemdaten mit Paiza liest
Wie schreibe ich Ruby to_s in Python
Zusammenfassung des Schreibens von AWS Lambda
Wie schreibe ich pydoc und mehrzeilige Kommentare
Wie man offline in Echtzeit schreibt Ich habe versucht, E12 mit Python zu lösen
So schreiben Sie einen Komponententest für den URL-Abruf in GAE / P.
Das 18. Offline-Echtzeit-Schreibproblem in Python
Wie schreibe ich ein benanntes Tupeldokument im Jahr 2020?
[Go] So schreiben oder rufen Sie eine Funktion auf
Das 19. Offline-Echtzeit-Schreibproblem in Python
So schreiben Sie eine ShellScript-Bash-Case-Anweisung
So schreiben Sie eine GUI mit dem Befehl maya
[Python] Versuchen Sie, die coole Antwort auf das FizzBuzz-Problem zu lesen
So schreiben Sie in Python die Verkettung von Zeichenfolgen in mehrere Zeilen
So schreiben Sie einen Listen- / Wörterbuchtyp von Python3
[Python] So schreiben Sie eine Dokumentzeichenfolge, die PEP8 entspricht
Das 14. Referenzproblem beim Offline-Schreiben in Echtzeit mit Python
Wie man schneller schreibt, wenn man numpy wie deque verwendet
Vergleichen Sie, wie die Verarbeitung für Listen nach Sprache geschrieben wird
[Einführung in Python] So schreiben Sie sich wiederholende Anweisungen mit for-Anweisungen