
Little Puzzle: Permutations and Derangements - idiomatic-fu
http://idiomatic-fu.appspot.com/puzzle/3003/view
======
spaghetti

        int N = 0;
    
        void printV(vector<int> v){ 
            for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl; 
        }
    
        void f(int index, vector<int> v){
    
            if(index == N){ 
                printV(v); 
                return; 
            }
    
            for(int i = 0; i < N; i++){ 
                if(i != index){ 
                    if(find(v.begin(), v.end(), i) == v.end()){ // hmmm
                        vector<int> t = v; 
                        t[index] = i; 
                        f(index + 1, t); 
                    } 
                } 
            }
    
        }
    
        /* print all derangements for ints 0 to n-1*/ 
    
        void PrintDerangements(int n){
            N = n; 
            vector<int> vInit(N, -1); 
            f(0, vInit);
        }

