3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class LookAndSay { private static function tokenize($input) { $currentDigit = substr($input, 0, 1); $n = 0; $result = []; foreach(str_split($input) as $digit) { if($currentDigit !== $digit) { $result[] = [$currentDigit, $n]; $n = 0; $currentDigit = $digit; } $n++; } $result[] = [$currentDigit, $n]; return $result; } public static function transform($input) { $tokens = self::tokenize($input); $result = ''; foreach($tokens as $token) { list($digit, $n) = $token; $result .= $n . $digit; } return $result; } } $input = '3113322113'; for($i = 0; $i < 40; $i++) {gc_collect_cycles(); $input = LookAndSay::transform($input);} print strlen($input);
Output for 7.0.0 - 7.1.7, 7.2.0
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /in/NPnJ8 on line 11
Process exited with code 255.
Output for 5.4.21, 7.1.10

Process exited with code 137.
Output for 5.6.8 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 72 bytes) in /in/NPnJ8 on line 11
Process exited with code 255.
Output for 5.4.10 - 5.4.20, 5.4.22 - 5.5.35
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 64 bytes) in /in/NPnJ8 on line 11
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NPnJ8 on line 8
Process exited with code 255.