Created
December 10, 2014 18:08
-
-
Save greydnls/d47deaf72b91a76b700b to your computer and use it in GitHub Desktop.
Rule 110
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$lines = array(); | |
$first_line = array_fill(0, 51, '*'); | |
$first_line[24] = '/'; | |
$lines[] = $first_line; | |
$rules = array( | |
'///'=> '*', | |
'//*' => '/', | |
'/*/'=> '/', | |
'/**' =>'*', | |
'*//'=> '/', | |
'*/*' => '/', | |
'**/'=> '/', | |
'***' => '*' | |
); | |
for ($i = 0; $i< 10; $i++) | |
{ | |
$line = array(); | |
for($j = 0; $j< 51; $j++) | |
{ | |
$pattern = (string)implode('', array_slice(end($lines), $j - 1, 3)); | |
$value = (strlen($pattern) == 3 && isset($rules[$pattern])) ? $rules[$pattern] : '*'; | |
$line[] = $value; | |
} | |
$lines[] = $line; | |
} | |
foreach ($lines as $line) | |
{ | |
foreach ($line as $piece) | |
{ | |
echo $piece; | |
} | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment