#include <iostream>
#include <vector>
void generate_all_random_permutations( int min, int max, std::size_t length,
std::ostream& stm,
std::vector<int> generated_so_far = {} )
{
if( length == 0 )
{
for( int v : generated_so_far ) stm << v ;
stm << '\n' ;
}
else
{
for( int v = min ; v <= max ; ++v )
{
generated_so_far.push_back(v) ;
generate_all_random_permutations( min, max, length-1, stm, generated_so_far ) ;
generated_so_far.pop_back() ;
}
}
}
int main()
{
generate_all_random_permutations( 1, 3, 4, std::cout ) ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdm9pZCBnZW5lcmF0ZV9hbGxfcmFuZG9tX3Blcm11dGF0aW9ucyggaW50IG1pbiwgaW50IG1heCwgc3RkOjpzaXplX3QgbGVuZ3RoLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RkOjpvc3RyZWFtJiBzdG0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGQ6OnZlY3RvcjxpbnQ+IGdlbmVyYXRlZF9zb19mYXIgPSB7fSAgKQp7CiAgICBpZiggbGVuZ3RoID09IDAgKQogICAgewogICAgICAgIGZvciggaW50IHYgOiBnZW5lcmF0ZWRfc29fZmFyICkgc3RtIDw8IHYgOwogICAgICAgIHN0bSA8PCAnXG4nIDsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBmb3IoIGludCB2ID0gbWluIDsgdiA8PSBtYXggOyArK3YgKQogICAgICAgIHsKICAgICAgICAgICBnZW5lcmF0ZWRfc29fZmFyLnB1c2hfYmFjayh2KSA7CiAgICAgICAgICAgZ2VuZXJhdGVfYWxsX3JhbmRvbV9wZXJtdXRhdGlvbnMoIG1pbiwgbWF4LCBsZW5ndGgtMSwgc3RtLCBnZW5lcmF0ZWRfc29fZmFyICkgOwogICAgICAgICAgIGdlbmVyYXRlZF9zb19mYXIucG9wX2JhY2soKSA7CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpCnsKICAgIGdlbmVyYXRlX2FsbF9yYW5kb21fcGVybXV0YXRpb25zKCAxLCAzLCA0LCBzdGQ6OmNvdXQgKSA7Cn0K