March 15, 2011, 8:48 p.m.
posted by stackme
Processing a String One Byte at a Time
Loop through each byte in the string with for. Figure counts the vowels in a string .
Processing each byte in a string
Processing a string a character at a time is an easy way to calculate the "Look and Say" sequence, as shown in Figure.
The "Look and Say" sequence
1 11 21 1211 111221 312211 13112221 1113213211 31131211131221 13211311123113112211
It's called the "Look and Say" sequence because each element is what you get by looking at the previous element and saying what's in it. For example, looking at the first element, 1, you say "one one." So the second element is "11." That's two ones, so the third element is "21." Similarly, that's one two and one one, so the fourth element is "1211," and so on.
Documentation on for at http://www.php.net/for; more about the "Look and Say" sequence at http://mathworld.wolfram.com/LookandSaySequence.html.