AiSc 10

Pasted Nov 4, 2026, 3:49 PM1 file41 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/ai10
untitled
import random

# Configuration
chromosome_length = 8
mutation_rate = 0.1

# Generate two random binary chromosomes (Parents)
parent1 = [
    random.randint(0, 1) for _ in range(chromosome_length)
]

parent2 = [
    random.randint(0, 1) for _ in range(chromosome_length)
]


def crossover_and_mutate(p1, p2):
    # Single-point crossover
    split = random.randint(1, chromosome_length - 1)

    child = p1[:split] + p2[split:]

    # Bit-flip mutation
    mutated_child = [
        bit if random.random() > mutation_rate else 1 - bit
        for bit in child
    ]

    return child, mutated_child, split


child, mutated, split_point = crossover_and_mutate(
    parent1, parent2
)

print("Parent 1:       ", parent1)
print("Parent 2:       ", parent2)

print(f"Crossover Child (Split at index {split_point}):", child)

print("Mutated Child:  ", mutated)

854 chars · codepastes.com