pythonnumpy
Ben Gorman

Ben Gorman

Life's a garden. Dig it.

Given a 1-million element array where each element is a random character in a-z, identify the starting index of every sequence of characters that spells waldo. Include sequences where at least 4 of the 5 characters match (e.g. waldo, 'wafdo', and xaldo but not wadlo).

import numpy as np
import string
 
generator = np.random.default_rng(123)
chars = generator.choice(list(string.ascii_lowercase), size=10**6, replace=True)
 
print(chars[:10])
# ['a' 'r' 'p' 'b' 'x' 'f' 'g' 'e' 'i' 'e']

Solution

This content is gated

Subscribe to one of the products below to gain access