Skip to content

Instantly share code, notes, and snippets.

@greydnls
Created December 10, 2014 18:08
Show Gist options
  • Save greydnls/d47deaf72b91a76b700b to your computer and use it in GitHub Desktop.
Save greydnls/d47deaf72b91a76b700b to your computer and use it in GitHub Desktop.
Rule 110
<?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