Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created February 11, 2016 13:45
Show Gist options
  • Save AndyNovo/eba4e5e2b16214599c29 to your computer and use it in GitHub Desktop.
Save AndyNovo/eba4e5e2b16214599c29 to your computer and use it in GitHub Desktop.
<?php
$myrack = "AAABNN";
$racks = [];
for($i = 0; $i < pow(2, strlen($myrack)); $i++){
$ans = "";
for($j = 0; $j < strlen($myrack); $j++){
//if the jth digit of i is 1 then include letter
if (($i >> $j) % 2) {
$ans .= $myrack[$j];
}
}
if (strlen($ans) > 1){
$racks[] = $ans;
}
}
$racks = array_unique($racks);
print_r($racks);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment