Computer Program
The following Python code generates a look-and-say sequence using lazy evaluation:
def look_and_say(member): while True: yield member breakpoints = ( + [i for i in range(1, len(member)) if member != member] + ) groups = :breakpoints] for i in range(1, len(breakpoints))] member = ''.join(str(len(group)) + group for group in groups) # Print the 10-element sequence beginning with "1" sequence = look_and_say("1") for i in range(10): print sequence.nextThe following JavaScript code uses a regular expression to generate the first 10 elements of a look-and-say sequence:
var number = "1"; var regexp = /(\d)\1*/g; for (var i = 0; i < 10; i++) { console.log(number); number = number.replace(regexp, function(fullmatch, symbol) { return fullmatch.length.toString + symbol; }); }Read more about this topic: Pea Pattern
Famous quotes containing the words computer and/or program:
“The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital computer or the gears of a cycle transmission as he does at the top of a mountain or in the petals of a flower.”
—Robert M. Pirsig (b. 1928)
“The Apache have a legend that the coyote brought them fire and that the bear in his hibernations communes with the spirits of the overworld and later imparts the wisdom gained thereby to the medicine men.”
—Administration in the State of Arizona, U.S. public relief program (1935-1943)