Untitled

mail@pastecode.io avatar
unknown
python
23 days ago
1.7 kB
1
Indexable
Never
types = {1: 7, 2: 12, 3: 0, 4: -3}


class Request:
    def __init__(self, request_type, request_id, past_request, additional_time):
        self.id = request_id
        self.type = request_type
        if self.type == 3 and self.id > 29:
            self.type = 4

        if not past_request:
            self.ddos_start = 0
            self.ddos_end = self.ddos_start + 2 if self.id < 30 else 1
            self.server_end = self.ddos_end + 3 + types[self.type]
        else:
            self.ddos_start = past_request.ddos_end
            self.ddos_end = self.ddos_start + 2 if self.id < 30 else 1
            self.server_end = max(self.ddos_end, past_request.server_end) + 3 + types[self.type] + additional_time

    def __repr__(self):
        return f"type: {self.type}\nid: {self.id}\nstart_ddos: {self.ddos_start}\nend_ddos: {self.ddos_end}\nend_servers {self.server_end}"


def gen_allreq(user_req, delay_req_user, scam_req):
    all_req = []

    for i in range(len(user_req) - 1):
        all_req.append(user_req[i])
        all_req += [scam_req] * delay_req_user

    all_req.append(user_req[i + 1])

    return all_req


requests = gen_allreq([2, 1, 2, 1, 2, 1, 2, 1, 2], 15, 3)
requests_processed = [Request(requests[0], 0, None, 0)]

cnt = 0

for i in range(1, len(requests)):
    if requests[i] == 3 and i > 29:
        cnt += 1
    if cnt == 50:
        cnt = 0
        request_processed = Request(requests[i], i, requests_processed[i - 1], 3)
    else:
        request_processed = Request(requests[i], i, requests_processed[i - 1], 0)

    requests_processed.append(request_processed)


print(max(requests_processed, key=lambda req: req.server_end))




Leave a Comment