Skip to content

code sprint sample source!! #20

@water0126

Description

@water0126

pyhon32 x86 기준으로 작성 되었습니다.
pyskein 다운 및 설치 하여야 작동 합니다.

from skein import skein256
from multiprocessing import Pool
import time
def values(rtn):
    pre = '0'
    sur = '1'
    pre_len = 0
    sur_len = 0
    b_pre = 0
    b_sur = 0
    length = len(rtn)
    for i in range(length):
        if b_pre == 0 and rtn[i] == pre: 
            pre_len = pre_len + 1
        else:
            b_pre = 1
        if b_sur == 0 and rtn[length - 1 - i] == sur :
            sur_len = sur_len + 1
        else : 
            b_sur = 1
        if((b_pre + b_sur) == 2 ):
            break

    return (pow(pre_len, 2)* R + pow(sur_len, 2)*B)  

def getXor(s1, s2):
    msg1 = bytes(s1, "ascii")
    msg2 = bytes(s2, "ascii")

    rtn = bin(int(skein256(msg1).hexdigest(),16) ^ int(skein256(msg2).hexdigest(),16))[2:].zfill(256)
    return rtn

def makes1(trans1, trans2):
        if(len(trans1) == M ) :
            makes2(trans1, trans2,)
        for i in char_list:
            rtns1 = trans1 + str(i)
            if(len(rtns1) < M) :
                makes1(rtns1, trans2)
            else :
                makes2(rtns1, trans2,)

def makes2(rtns1, trans2):
    if(len(trans2) == M ) : 
        getMaxValue(rtns1, trans2)
    for i in char_list:
        rtns2 = trans2 + str(i)
        if(len(rtns2) < M) :
            makes2(rtns1, rtns2)
        else :
            #return
            getMaxValue(rtns1, rtns2)

def getMaxValue(rtns1, rtns2):
    global maxValue
    global maxs1
    global maxs2
    xor = getXor(rtns1, rtns2)
    value = values(xor)
    #print(rtns1, rtns2, value)
    if (value > maxValue) : 
        maxValue = value
        maxs1 = rtns1
        maxs2 = rtns2

start_time = time.time()
char_list = []
for i in range(48, 123):
    if((i > 57 and i < 65) or (i>90 and i<97)):
        continue
    char_list.append(chr(i))
maxValue = 0

M = 3
s1 = 'B'
s2 = 'A'
maxs1 = s1
maxs2 = s2
R = 1
B = 1
makes1(s1, s2)

end_time = time.time()
print(maxs1, maxs2)
print(maxValue)
print(end_time - start_time)


#params = input('')
#param = params.split(' ')
#N = int(param.pop(0))
#M = int(param.pop(0))
#R = int(param.pop(0))
#B = int(param.pop(0))

#parms2 = input('')
#s1 = param.pop(0)
#s2 = param.pop(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions