Skip to content

Instantly share code, notes, and snippets.

@rianorie
Created July 10, 2014 22:48
Show Gist options
  • Save rianorie/cb554b8b1641c7908af2 to your computer and use it in GitHub Desktop.
Save rianorie/cb554b8b1641c7908af2 to your computer and use it in GitHub Desktop.
skilleo Squad Formation Curse
<?php
$n = 6;
$k = 3;
$squads = 0;
$pattern = 'R??L?R';
$curse = '';
for($i = 0; $i < $k; $i++) { $curse .= 'R'; }
$positions = substr_count($pattern, '?');
$replacements = [];
for($i = 0; $i <= pow(2, $n); $i++) {
$tmp = substr(sprintf("%0".$positions."d", decbin($i)), $positions-($positions*2));
$replacements[$tmp] = str_split($tmp);
}
foreach($replacements as $r) {
$tmp = $pattern;
$i = 0;
while(($pos = strpos($tmp, '?')) !== false) {
$tmp = substr_replace($tmp, ($r[$i] ? 'R' : 'L'), $pos, 1);
$i++;
}
if (strpos($tmp, $curse) === false) {
$squads++;
}
}
echo $squads."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment