示例#1
0
def solve():
    orig = ' iT iTiI T TTiTIITITIITTi iTiIIT'
    bars = Bars(orig)
    bars_pos = len(orig) - 7
    solve_x(bars, bars_pos, "")
    if False:
        bars.prev()
        print(str(bars))
        for c in string.ascii_uppercase:
            new_bars = Bars(bars)
            bars_pos = len(orig) - 7
            code = encode_morse(c)
            rcode = code[::-1]
            for i in rcode:
                new_bars.xor(bars_pos, i)
                bars_pos -= 1
                bars_pos %= len(bars)
            print("new_bars={0} xor={1}".format(str(new_bars), code))
            print("prv_bars={0}".format(str(new_bars.prev())))
示例#2
0
def solve2():
    h = 1758412232636122750
    s = bars_num_to_str(h)
    print("bars.str:" + s)
    barsd = Bars(s)
    bars = Bars(' ' + str(barsd))
    print("bars.num:" + str(bars.num()))
    bars_len = len(bars)
    print("bars.len=" + str(bars_len))
    bars_pos = bars_len - 1
    answer = []
    while 0 <= bars_pos:
        found = False
        for c in string.ascii_uppercase:
            tmp_bars = Bars(bars)
            tmp_bars.prev()
            tmp_pos = bars_pos
            code = encode_morse(c)
            rcode = reverse_str(code)
            ok = 0
            for i in rcode:
                tmp_bars.xor(tmp_pos, i)
                if tmp_bars[tmp_pos] != ' ':
                    ok += 1
                tmp_pos -= 1; tmp_pos %= bars_len
            if len(code) - 1 <= ok:
                found = True
                bars.prev()
                #print("c=" + c)
                answer.append(c)
                for i in rcode:
                    bars.xor(bars_pos, i)
                    bars_pos -= 1; bars_pos %= bars_len
                break
        if found == False:
            print("failed")
            break
    print("bars=" + str(bars))