Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // https://twitter.com/marsroverdriver/status/346776078645342208
- for ($test = 1 << 16; 0 !== $test; --$test)
- {
- $text = '';
- for ($length = rand(8, 10); 0 !== $length; --$length)
- {
- if (0 === rand(0, 1))
- {
- $text .= 'o';
- }
- else
- {
- $text .= chr(rand(ord('a'), ord('z')));
- }
- }
- $reference = preg_match('/^[^o][^o]o[^o][^o]o[^o]o[^o][^o]$/', $text);
- $result = preg_match('/^[^o](?:[^o]o[^o]){2}o[^o]{2}$/', $text);
- if ($reference !== $result)
- {
- echo 'Test failed', PHP_EOL, $text, PHP_EOL;
- var_dump($result);
- var_dump($reference);
- die();
- }
- }
- echo 'Test passed', PHP_EOL;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment