1.4. Processing a String One Character at a Time1.4.2. SolutionLoop through each character in the string with for. This example counts the vowels in a string:
1.4.3. DiscussionProcessing a string a character at a time is an easy way to calculate the "Look and Say" sequence:
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. 1.4.4. See AlsoDocumentation on for at http://www.php.net/for; more about the "Look and Say" sequence at http://mathworld.wolfram.com/LookandSaySequence.html.
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|