May 17, 2013 at 6:35pm UTC
1 2 3 4 5 6
if ( BOOL[POSITION] )
{
std::cout << "true; " << std::flush;
} else {
std::cout << "false; " << std::endl;
}
Actually I see what you are trying to do now..and the possible combinations is !10 = 3628800
There are probably a few ways to do that by like reanaging the array that many times I guess I'll try and think of a way to do that
Last edited on May 17, 2013 at 7:16pm UTC
May 17, 2013 at 6:42pm UTC
sorry, i think i did not explain it right.
my problem is not with the output, but with creating all possible combinations.
May 17, 2013 at 6:45pm UTC
Last edited on May 17, 2013 at 6:45pm UTC
May 17, 2013 at 7:04pm UTC
next_permutation won't help in that case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <bitset>
#include <iomanip>
#include <iostream>
int main()
{
const int n = 10;//How many bools you have
std::cout << std::boolalpha; //Show bools as true/false
for (unsigned long x = 0; x < 1ul << n; ++x) {
std::bitset<n> combination(x);
for (int i = 0; i < n; ++i)
std::cout << std::setw(5) << combination[i] << "; " ;
std::cout << std::endl;
}
}
false; false; false; false; false; false; false; false; false; false;
true; false; false; false; false; false; false; false; false; false;
false; true; false; false; false; false; false; false; false; false;
true; true; false; false; false; false; false; false; false; false;
false; false; true; false; false; false; false; false; false; false;
true; false; true; false; false; false; false; false; false; false;
false; true; true; false; false; false; false; false; false; false;
true; true; true; false; false; false; false; false; false; false;
false; false; false; true; false; false; false; false; false; false;
true; false; false; true; false; false; false; false; false; false;
false; true; false; true; false; false; false; false; false; false;
true; true; false; true; false; false; false; false; false; false;
//etc...
//There is 1024 lines
Sample with n=8 (ideone does not like large outputs):
http://ideone.com/hrsABB
EDIT: Fancier output. Stolen from
LB :P
EDIT 2: More black magic
Last edited on May 17, 2013 at 7:47pm UTC
May 17, 2013 at 7:08pm UTC
I created a solution show me you are trying and I might show you it =p
here is a snippet of the output
true; true; true; true; true; true; true; true; true; true.
false; true; true; true; true; true; true; true; true; true.
true; false; true; true; true; true; true; true; true; true.
true; true; false; true; true; true; true; true; true; true.
true; true; true; false; true; true; true; true; true; true.
true; true; true; true; false; true; true; true; true; true.
true; true; true; true; true; false; true; true; true; true.
true; true; true; true; true; true; false; true; true; true.
true; true; true; true; true; true; true; false; true; true.
true; true; true; true; true; true; true; true; false; true.
true; true; true; true; true; true; true; true; true; false.
false; false; true; true; true; true; true; true; true; true.
false; true; false; true; true; true; true; true; true; true.
false; true; true; false; true; true; true; true; true; true.
false; true; true; true; false; true; true; true; true; true.
false; true; true; true; true; false; true; true; true; true.
false; true; true; true; true; true; false; true; true; true.
false; true; true; true; true; true; true; false; true; true.
false; true; true; true; true; true; true; true; false; true.
false; true; true; true; true; true; true; true; true; false.
true; false; false; true; true; true; true; true; true; true.
true; false; true; false; true; true; true; true; true; true.
true; false; true; true; false; true; true; true; true; true.
true; false; true; true; true; false; true; true; true; true.
true; false; true; true; true; true; false; true; true; true.
true; false; true; true; true; true; true; false; true; true.
true; false; true; true; true; true; true; true; false; true.
true; false; true; true; true; true; true; true; true; false.
true; true; false; false; true; true; true; true; true; true.
true; true; false; true; false; true; true; true; true; true.
true; true; false; true; true; false; true; true; true; true.
true; true; false; true; true; true; false; true; true; true.
true; true; false; true; true; true; true; false; true; true.
true; true; false; true; true; true; true; true; false; true.
true; true; false; true; true; true; true; true; true; false.
true; true; true; false; false; true; true; true; true; true.
true; true; true; false; true; false; true; true; true; true.
true; true; true; false; true; true; false; true; true; true.
true; true; true; false; true; true; true; false; true; true.
true; true; true; false; true; true; true; true; false; true.
true; true; true; false; true; true; true; true; true; false.
true; true; true; true; false; false; true; true; true; true.
true; true; true; true; false; true; false; true; true; true.
true; true; true; true; false; true; true; false; true; true.
true; true; true; true; false; true; true; true; false; true.
true; true; true; true; false; true; true; true; true; false.
true; true; true; true; true; false; false; true; true; true.
true; true; true; true; true; false; true; false; true; true.
true; true; true; true; true; false; true; true; false; true.
true; true; true; true; true; false; true; true; true; false.
true; true; true; true; true; true; false; false; true; true.
true; true; true; true; true; true; false; true; false; true.
true; true; true; true; true; true; false; true; true; false.
true; true; true; true; true; true; true; false; false; true.
true; true; true; true; true; true; true; false; true; false.
true; true; true; true; true; true; true; true; false; false.
false; false; false; true; true; true; true; true; true; true.
false; false; true; false; true; true; true; true; true; true.
false; false; true; true; false; true; true; true; true; true.
false; false; true; true; true; false; true; true; true; true.
false; false; true; true; true; true; false; true; true; true.
false; false; true; true; true; true; true; false; true; true.
false; false; true; true; true; true; true; true; false; true.
false; false; true; true; true; true; true; true; true; false.
false; true; false; false; true; true; true; true; true; true.
false; true; false; true; false; true; true; true; true; true.
false; true; false; true; true; false; true; true; true; true.
false; true; false; true; true; true; false; true; true; true.
false; true; false; true; true; true; true; false; true; true.
false; true; false; true; true; true; true; true; false; true.
false; true; false; true; true; true; true; true; true; false.
false; true; true; false; false; true; true; true; true; true.
false; true; true; false; true; false; true; true; true; true.
false; true; true; false; true; true; false; true; true; true.
false; true; true; false; true; true; true; false; true; true.
false; true; true; false; true; true; true; true; false; true.
false; true; true; false; true; true; true; true; true; false.
false; true; true; true; false; false; true; true; true; true.
false; true; true; true; false; true; false; true; true; true.
false; true; true; true; false; true; true; false; true; true.
false; true; true; true; false; true; true; true; false; true.
false; true; true; true; false; true; true; true; true; false.
false; true; true; true; true; false; false; true; true; true.
false; true; true; true; true; false; true; false; true; true.
false; true; true; true; true; false; true; true; false; true.
false; true; true; true; true; false; true; true; true; false.
false; true; true; true; true; true; false; false; true; true.
false; true; true; true; true; true; false; true; false; true.
false; true; true; true; true; true; false; true; true; false.
false; true; true; true; true; true; true; false; false; true.
false; true; true; true; true; true; true; false; true; false.
false; true; true; true; true; true; true; true; false; false.
true; false; false; false; true; true; true; true; true; true.
true; false; false; true; false; true; true; true; true; true.
true; false; false; true; true; false; true; true; true; true.
true; false; false; true; true; true; false; true; true; true.
true; false; false; true; true; true; true; false; true; true.
true; false; false; true; true; true; true; true; false; true.
true; false; false; true; true; true; true; true; true; false.
true; false; true; false; false; true; true; true; true; true.
true; false; true; false; true; false; true; true; true; true.
true; false; true; false; true; true; false; true; true; true.
true; false; true; false; true; true; true; false; true; true.
true; false; true; false; true; true; true; true; false; true.
true; false; true; false; true; true; true; true; true; false.
true; false; true; true; false; false; true; true; true; true.
true; false; true; true; false; true; false; true; true; true.
true; false; true; true; false; true; true; false; true; true.
true; false; true; true; false; true; true; true; false; true.
true; false; true; true; false; true; true; true; true; false.
true; false; true; true; true; false; false; true; true; true.
true; false; true; true; true; false; true; false; true; true.
true; false; true; true; true; false; true; true; false; true.
true; false; true; true; true; false; true; true; true; false.
true; false; true; true; true; true; false; false; true; true.
true; false; true; true; true; true; false; true; false; true.
true; false; true; true; true; true; false; true; true; false.
true; false; true; true; true; true; true; false; false; true.
true; false; true; true; true; true; true; false; true; false.
true; false; true; true; true; true; true; true; false; false.
true; true; false; false; false; true; true; true; true; true.
Total permuations: 1023
Last edited on May 17, 2013 at 7:12pm UTC
May 17, 2013 at 7:10pm UTC
I created a solution too and posted it. Now try to understand it :)
May 17, 2013 at 7:13pm UTC
Next permutation worked for me
your code is a bit nicer though
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
void output( std::vector<bool > array )
{
short count = 0;
for ( std::vector<bool >::iterator it = array.begin(); it != array.end(); ++it )
{
std::cout << *it << std::flush;
if ( count < 9 )
{
std::cout << "; " << std::flush;
} else {
std::cout << "." << std::endl;
}
++count;
}
}
int main()
{
std::vector<bool > array( 10 , true );
short permutations = 0;
std::cout << std::boolalpha;
for ( unsigned int i = 0; i < 10; i++ )
{
do
{
output( array );
++permutations;
} while ( std::next_permutation( array.begin() , array.end() ) );
array[ i ] = false ;
}
output( array );
++permutations;
std::cout << "Total permuations: " << permutations << std::endl;
}
[edit]UPDATED CODE[/edit]
Last edited on May 17, 2013 at 7:34pm UTC
May 17, 2013 at 7:17pm UTC
are you guys competing? :P
thanks for the help, i got the idea :)
May 17, 2013 at 7:18pm UTC
Ah, if you help next_permutation a little it would work too. I thought it would take more work...
And either you are missing "all false" combination (btw, it is combinations, not permutations) or your permutations counter is off by one.
EDIT: You are missing "all false" combination
Edit 2: Sorry, You were right about permutation. Shame on me.
Last edited on May 17, 2013 at 7:31pm UTC
May 17, 2013 at 7:21pm UTC
well if it is combination I am completely wrong I did it for the permuatations. and yeah sorry forgot to put the all false in there I made it stop right before that.
http://www.mathsisfun.com/combinatorics/combinations-permutations.html
website wrote:If the order doesn't matter, it is a Combination.
If the order does matter it is a Permutation.
Also I didn't know about boolalpha thanks I'll update my code asap
Last edited on May 17, 2013 at 7:24pm UTC
May 17, 2013 at 7:23pm UTC
Recursive:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <iostream>
#include <vector>
#include <iomanip>
void print( const std::vector<bool >& seq )
{
for ( bool b : seq ) std::cout << std::setw(5) << b << "; " ;
std::cout << '\n' ;
}
void generate( std::vector<bool >& seq, std::vector<bool >::iterator from )
{
if ( from == seq.end() ) print(seq) ;
else
{
*from = false ;
generate( seq, from+1 ) ;
*from = true ;
generate( seq, from+1 ) ;
}
}
void generate( std::size_t n )
{
std::vector<bool > seq(n) ;
generate( seq, seq.begin() ) ;
}
int main()
{
std::cout << std::boolalpha ;
generate(5) ; // 2^5 sequences
}
http://ideone.com/irW7qE
Last edited on May 17, 2013 at 7:48pm UTC