ho trovato su questo sito questo codice che stampa le combinazioni possibili di 5 numeri
ora.... mi servirebbe farlo con javascript:codice:#include <iostream> #include <fstream> #include <cstdlib> class Combinations { private: int *Elements; int *Indexes; int Length; bool End; int i; public: Combinations (int *Elements,int NumElem) { this->Length = NumElem; this->Elements = new int[Length]; memset(this->Elements,0,Length * sizeof(int)); if (Length > 0) this->Indexes = new int[Length-1]; memset(this->Indexes,0,sizeof(int) * Length - 1); for (int i = 0; i < Length; i++) this->Elements[i] = Elements[i]; End = Length < 1; } bool hasNext() { return !End; } int* next () { if (End) return NULL; int *result = new int[this->Length]; memset(result,0,this->Length * sizeof(int)); for (int i = 0; i < Length; i++) result[i] = Elements[i]; for (i = 0; i < Length-1; i++) { int obj = result[i+Indexes[i]]; for (int j = i+Indexes[i]; j > i; j--) result[j] = result[j-1]; result[i] = obj; } int carry = 1; for (i = Length-2; i >= 0; i--) { Indexes[i] += carry; if (Indexes[i] > Length-i-1) { Indexes[i] = 0; carry = 1; } else carry = 0; } if (carry == 1) End = true; return result; } }; using namespace std; int main(void) { int elems; cout <<"Number Generator by Peppe Mercury & Ciccio Cat, 2007" <<endl <<endl; cout <<"Quanti elementi vuoi inserire?" << endl; cin >> elems; int *pNumbers = new (nothrow) int[elems]; cout <<"Inserire gli elementi." << endl; for (int i = 0; i < elems; i++) cin >> pNumbers[i]; cout << endl; Combinations *c = new Combinations(pNumbers,elems); ofstream f; f.open("Combo.txt",ios::out); while (c->hasNext()) { int *arr = c->next (); for (int i = 0; i < elems; i++) { cout << arr[i] << " "; f << arr[i] << " "; } cout <<endl; f <<endl; delete arr; } f.close(); cout <<"Combinazioni salvate nel file Combo.txt " << endl; system("PAUSE"); delete[] pNumbers; delete c; return 0; }
vorrei che le combinazioni siano inserite in un link es. http:www.html.it/*****.html
si può fare ma io sono un capra in javascript, mi aiutate?

Rispondi quotando
