Tsukihjy's picture
download
raw
5.25 kB
import random
import string
def generate_string(length):
"""Generate a random string of given length"""
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
def generate_repetitive_string(length, pattern_length=3):
"""Generate a string with repetitive patterns"""
pattern = ''.join(random.choice(string.ascii_lowercase) for _ in range(pattern_length))
result = (pattern * (length // pattern_length + 1))[:length]
return result
def generate_palindromic_string(length):
"""Generate a palindromic string"""
half = length // 2
first_half = ''.join(random.choice(string.ascii_lowercase) for _ in range(half))
if length % 2 == 0:
return first_half + first_half[::-1]
else:
middle = random.choice(string.ascii_lowercase)
return first_half + middle + first_half[::-1]
def generate_operations(string_length, num_ops):
"""Generate a mix of operations"""
operations = []
current_length = string_length
for _ in range(num_ops):
op_type = random.choices(['Q', 'R', 'I'], weights=[0.4, 0.3, 0.3])[0]
if op_type == 'Q':
x = random.randint(1, current_length)
y = random.randint(1, current_length)
operations.append(f"Q {x} {y}")
elif op_type == 'R':
x = random.randint(1, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"R {x} {d}")
else: # Insert
x = random.randint(0, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"I {x} {d}")
current_length += 1
if current_length > 100000:
current_length = 100000
return operations
def generate_adversarial_queries(string_length, num_queries):
"""Generate adversarial query patterns"""
operations = []
# Edge case queries
operations.append(f"Q 1 1")
operations.append(f"Q {string_length} {string_length}")
operations.append(f"Q 1 {string_length}")
# Adjacent positions
for i in range(min(10, string_length - 1)):
pos = random.randint(1, string_length - 1)
operations.append(f"Q {pos} {pos + 1}")
# Far apart positions
for _ in range(min(5, num_queries - len(operations))):
x = random.randint(1, string_length // 2)
y = random.randint(string_length // 2 + 1, string_length)
operations.append(f"Q {x} {y}")
return operations
def construct_inputs():
inputs = []
# Test case 1: Small string with many operations
initial_string = "abcabc"
operations = [
"Q 1 4",
"Q 2 5",
"R 3 a",
"Q 1 4",
"I 0 x",
"Q 2 5"
]
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
# Test case 2: Repetitive pattern string
initial_string = generate_repetitive_string(50, 3)
operations = generate_operations(50, 30)
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
# Test case 3: Palindromic string
initial_string = generate_palindromic_string(100)
operations = generate_adversarial_queries(100, 20)
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
# Test case 4: Large string with maximum operations
initial_string = generate_string(1000)
operations = generate_operations(1000, 1000)
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
# Test case 5: Single character string
initial_string = "a"
operations = [
"Q 1 1",
"I 1 b",
"Q 1 2",
"R 2 a",
"Q 1 2"
]
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
# Test case 6: All same characters
initial_string = "a" * 200
operations = []
for _ in range(50):
x = random.randint(1, 200)
y = random.randint(1, 200)
operations.append(f"Q {x} {y}")
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
# Test case 7: Maximum length with many inserts
initial_string = generate_string(500)
operations = []
current_len = 500
for i in range(100):
if i % 3 == 0 and current_len < 100000:
pos = random.randint(0, current_len)
char = random.choice(string.ascii_lowercase)
operations.append(f"I {pos} {char}")
current_len += 1
elif i % 3 == 1:
pos = random.randint(1, current_len)
char = random.choice(string.ascii_lowercase)
operations.append(f"R {pos} {char}")
else:
x = random.randint(1, current_len)
y = random.randint(1, current_len)
operations.append(f"Q {x} {y}")
test_case = initial_string + "\n" + str(len(operations)) + "\n" + "\n".join(operations)
inputs.append(test_case)
return inputs

Xet Storage Details

Size:
5.25 kB
·
Xet hash:
408c71026fbdef388e6aefce80505f6f06fa9e11a30e60680b273a0751a853a9

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.