Printing Boolean Input Combinations in Scala

Someone at school recently asked me to help him write some code in Scala to print out the [latex]2^n[/latex] Boolean input combinations that are possible with [latex]n[/latex] variables. I decided to start off with [latex]n=4[/latex] variables to keep things simple and verifiable. After a couple of minutes of hacking around, I came up with the following code:The cool part is the shifting modulus check. I'm actually kind of proud of it. It enabled me to write the code using only two loops! Here is the result: -a -b -c -d +a -b -c -d -a +b -c -d +a +b -c -d -a -b +c -d +a -b +c -d -a +b +c -d +a +b +c -d -a -b -c +d +a -b -c +d -a +b -c +d +a +b -c +d -a -b +c +d +a -b +c +d -a +b +c +d +a +b +c +d Also, please note that this is probably, by no means, the most functional way to do this. It was merely an attempt at hacking together some code that just gets the job done. If I have time, I will write up some posts on functional ways to produce both combinations and permutations in Scala.