Assignment Search Framework
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
combinatorics.cpp File Reference

Functions

bool get_next_combo_helper (vector< unsigned > &combo, unsigned max_num, unsigned pos, bool reset_rest)
 
bool get_next_combo (vector< unsigned > &combo, unsigned k, unsigned n, bool first_combo)
 
void get_rand_permutation (vector< unsigned > &perm, unsigned perm_size)
 
uint64_t get_64_bit_factorial (unsigned n)
 
uint64_t get64BitnUpperk (unsigned n, unsigned k)
 
bool read_in_permutations (string file_name, vector< vector< unsigned > > &perms)
 

Function Documentation

uint64_t get64BitnUpperk ( unsigned  n,
unsigned  k 
)

Returns the value of n!/k! for the given integers.

No guarantees on what happens if there is an overflow.

Todo:
Figure out what should happen when an overflow happens.
Parameters
nThe denominator of the n!/k! term.
kThe numerator of the n!/k! term.
Returns
The value of n!/k! for the given integers.
uint64_t get_64_bit_factorial ( unsigned  n)

Returns n! for the given value of n.

If n is too large, it just returns the highest value stored in 64 bits.

Parameters
nThe value to take the factorial of.
Returns
The factorial value of the given value.
bool get_next_combo ( vector< unsigned > &  combo,
unsigned  k,
unsigned  n,
bool  first_combo 
)
bool get_next_combo_helper ( vector< unsigned > &  combo,
unsigned  max_num,
unsigned  pos,
bool  reset_rest 
)

Helper function for get_next combo.

Given a combination, a position, and whether we are at a reset, finds the next combo if one exists. This means incrementing the element at the given position if possible, and then resetting the remaining values to the smallest values left. If its not possible, it returns false.

Parameters
comboThe current combo which is updated to get the next combo.
max_numThe maximum element value.
posThe current position.
reset_restWhether the combo should be reset starting from the given position.
Returns
If we successfully found the next combination.
void get_rand_permutation ( vector< unsigned > &  perm,
unsigned  perm_size 
)
bool read_in_permutations ( string  file_name,
vector< vector< unsigned > > &  perms 
)