I was posed the following inquiry: “Basically I have 6 boolean variables and I need to document every possible true/false combination. I’m having difficulty finding a basic method to write all combinations out without repeating.”
I offered the following solution (yes, in PHP):
for($var = 0; $var <= 63; $var++) {
echo str_pad(str_replace(“0”, “F”, str_replace(“1”, “T”, decbin($var))), 6, “F
”, STR_PAD_LEFT) . ”\\n”;
}
?>
It simply counts from zero to 64, prints that in binary, and I have it manually toggle 0 to ‘F’ and 1 to ‘T’ for true/false. The str_pad is called due the fact that the first few numbers will ‘not fit’ with the diagram properly, and there’s no sense to manually fill it.
The reply I was given to this was: “Brilliant, and insane – yet, it’s in PHP, so I’m beside myself.” Gee, thanks. :)