Skip to content

Instantly share code, notes, and snippets.

@thomasruiz
Last active December 6, 2015 14:23
Show Gist options
  • Save thomasruiz/d24987734c5abde3ce86 to your computer and use it in GitHub Desktop.
Save thomasruiz/d24987734c5abde3ce86 to your computer and use it in GitHub Desktop.
<?php
$l = str_repeat('0', 1000000);
$i = file('i');
foreach ($i as $s) {
$tok = strtok($s, ' ');
$instruction = 1;
$c = '';
if ($tok === 'toggle') {
$instruction = 0;
} else {
if (strtok(' ') === 'on') {
$c = '1';
} else {
$c = '0';
}
}
$x = strtok(',');
$y = strtok(' ');
strtok(' ');
$d = strtok(',');
$e = strtok("\n");
while ($x <= $d) {
$z = $y;
while ($z <= $e) {
$a = $l[$x + $z * 1000];
if ($instruction === 0) {
$c = $a === '1' ? '0' : '1';
}
$l[$x + $z * 1000] = $c;
$z += 1;
}
$x += 1;
}
}
echo substr_count($l, '1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment