Spaces:
Sleeping
Sleeping
| import re | |
| def clean_text(text): | |
| return re.sub(r'\s+', ' ', text).strip() | |
| def get_pi_digits(n=100): | |
| with open('pi_digits.txt', 'r') as f: | |
| digits = f.read().replace('.', '').replace('\n', '') | |
| return [int(d) for d in digits[:n] if d.isdigit()] | |
| def pi_shard(text, max_chunks=50): | |
| text = clean_text(text) | |
| pi_digits = get_pi_digits() | |
| chunks = [] | |
| index = 0 | |
| i = 0 | |
| while index < len(text) and len(chunks) < max_chunks: | |
| length = pi_digits[i % len(pi_digits)] + 1 | |
| chunk = text[index:index + length * 50] | |
| overlap = pi_digits[(i+1) % len(pi_digits)] * 5 | |
| chunks.append(chunk) | |
| index += length * 50 - overlap | |
| i += 1 | |
| return chunks | |