Like what:
The first number is: 1.
Look at the first number you can say a 1, then the second number is: 11.
Look at the second number you can say 2 1, that is, the third number is: 21.
Look at the third number you can say a 2, a 1, that is, the fourth number is: 1211.
Look at the fourth number you can say a 1, a 2, 2 1, that is, the fifth number is: 111221.
............
According to the detailed instructions, see: http://en.wikipedia.org/wiki/Look-and-say_sequence
This sequence is implemented in PHP as follows:
Copy the Code code as follows:
function Look ($STR)
{
$len = strlen ($STR);
$count = 0;
$result = ";
$temp = $str [0];
for ($i =0; $i < $len; $i + +)
{
if ($temp! = $str [$i])
{
$result. = $count. $temp;
$temp = $str [$i];
$count = 1;
}
Else
{
$count + +;
}
}
$result. = $count. $temp;
return $result;
}
$test _str = "1";
echo $test _str. '
';
for ($i =0; $i <10; $i + +)
{
$test _str=look ($test _str);
Print $test _str. "
";
}
Note that for loops in the look function, when $len-1, the $result does not accumulate the statistics of the last digit, so it accumulates again once the loop is complete.
The result of the final output:
1
11
21st
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
Author: ywxgod
The above describes the Hotmail Outlook look and Say sequence PHP implementation code, including the Hotmail Outlook content, I hope the PHP tutorial interested in a friend helpful.