#37774: 字串產生機


BensonDC (python戰士)

學校 : 不指定學校
編號 : 240921
來源 : [1.175.217.87]
最後登入時間 :
2024-03-27 12:33:26
g751. 聽說只有5%的人能通過這題 -- Ststone | From: [36.238.130.174] | 發表日期 : 2023-10-06 23:02

import random
import string
import datetime

def generate_random_string(string_length):
    """Generate a random string of fixed length """
    letters = string.ascii_letters
    return ''.join(random.choice(letters) for i in range(string_length))


def get_score(random_string):
    answer_array = [4,8,7,6,3,4,8,7,6,3,4,8,7,6,3,4,8,7,6,3,4,8,7,6,3]
    total = 0

    x1 = datetime.datetime.now().year
    x2 = datetime.datetime.now().month
    x3 = datetime.datetime.now().day

    def f(x:int):
        x = x%30000
        return ((x*x)+87-int(x/3)-(x%7))%48763

    def g(x:int):
        x = x%30000
        return ((x-1)*(x+2)+(x/4)-(x%3))%48763

    def q(x:int):
        x = x%30000
        x = x+x*x+(449*x)%48763
        return ((x%3)+(x%5)+(x%7)+(x%2)+(x%11)+(x%101))%48763

    def swap(a,b):
        return b,a

    day_lucky_number = int((f(x1)+g(x2)+q(x3))%48763)

    def random_swap():
        for i in range(len(answer_array)):
            seed = int((day_lucky_number+f(total)+g(total)+q(total))%48763)
            if(i%3==0):
                seed = int(((seed+f(answer_array[i]+day_lucky_number)))%48763)
            elif(i%3==1):
                seed = int(((seed+g(answer_array[i])))%48763)
            elif(i%3==2):
                seed = int(((seed+q(answer_array[i])))%48763)
            px,py = i,int((f(seed)+g(seed+day_lucky_number)+q(seed+day_lucky_number))%len(answer_array))
            answer_array[px],answer_array[py] = swap(answer_array[px],answer_array[py])

    a = random_string

    for i in a:
        total += ord(i)
        answer_array.append(ord(i))

    total = int((f(total)+g(total)+q(total))%48763)
    random_swap()

    score = 0

    for i in range(len(answer_array)):
        if(i%3==0):
            score = int(((score+f(answer_array[i])))%48763)
        elif(i%3==1):
            score = int(((score+g(answer_array[i]+day_lucky_number)))%48763)
        elif(i%3==2):
            score = int(((score+q(answer_array[i]+day_lucky_number)))%48763)

    score = round(score/487.63,2)
    return score


max_score = 0
while max_score <= 95:
    random_string_length = random.randint(1, 50)
    random_string = generate_random_string(random_string_length)
    score = get_score(random_string)
    if score > max_score:
        max_score = score
        winning_string = random_string

print("Final high score: ", max_score)
print("Winning string: ", winning_string)

 
ZeroJudge Forum