Created
July 10, 2014 22:48
-
-
Save rianorie/cb554b8b1641c7908af2 to your computer and use it in GitHub Desktop.
skilleo Squad Formation Curse
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 | |
$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