void main (void) { int x; FILE *F; if((F=fopen("Nex.log", "w`")) == NULL) return; fclose(F); if((F=fopen("Nex.log", "a")) == NULL) return; for(x=0; x<N; x++) P[x] = x + 1; perm(0, F); }
void perm(char *list, int i, int n) { int j, temp; if (i == n) { for (j = 0; j <= n; j++) printf ("%c", list[j]); printf(" "); } else { for (j = i; j <= n; j++) { SWAP(list[i], list[j], temp); perm(list, i+1, n); SWAP(list[i], list[j], temp); } } }
perm(int k) { int i; if(k==n) print(); else { for(i=k;i<=n;i++) { swap(&a[i],&a[k]); perm(k+1); swap(&a[i],&a[k]); } } }
void perm(int Pos, FILE *F) { int i, x, save; if(Pos == N) { for(i=0; i<N; i++) fprintf(F ,"%d ", P[i]); fprintf(F, " - %s\n", Parity ? "odd" : "even"); return; } save = Parity; perm(Pos +1, F); for(i = Pos +1; i< N; i++) { Parity = !Parity; swap(&P[Pos], &P[i]); perm(Pos +1, F); } Parity = save; x = P[Pos]; for(i = Pos +1; i< N; i++) P[i - 1] = P[i] ; P[N-1] = x; }
main() { int n=2; char s[N]; w[n]='\0'; clrscr(); printf("This is a char permutation program!\nPlease input a string:\n"); scanf("%s",s); puts("\nPlease input the char number of permuted:\n"); scanf("%d",&n); puts("The permuted chars are:\n"); perm(n,s); puts("\nPress any key to quit..."); getch(); }
void crypt::encrypt(char *nachr, int decr) { char(*schl)[KS] = decr ? schluessel + 15 : schluessel; char tmp[BS]; int i; perm(tmp, nachr, IP, BS); for (i = 8; i--;) { crypt_main(tmp, tmp + BS2, *schl); if (decr) schl--; else schl++; crypt_main(tmp + BS2, tmp, *schl); if (decr) schl--; else schl++; } perm(nachr, tmp, EP, BS); }
/** * @param nums: A list of integers. * @return: A list of unique permutations. */ void perm(vector<vector<int> > &res, vector<int> & nums, int k){ if(k == nums.size() ){ res.push_back(nums); return; } for(int i = k; i < nums.size(); ++i){ sort(nums.begin() + k, nums.end()); if(i == k || nums[i] != nums[i - 1]){ swap(nums[i], nums[k]); perm(res, nums, k + 1); swap(nums[i], nums[k]); } } }
void CNPLCM_CR_Basic_Freq::permute_latent_classes_by_nu(){ //reorder latent classes increasingly according to nuK. std::vector<int> new2old(par->K), old2new(par->K); std::vector<_CNPLCM_CR_Basic_Freq_mypair> s_index(par->K); for (int k = 0; k < par->K; k++){ s_index[k].first = 1.0 - par->nuK[k]; s_index[k].second = k; } std::sort(s_index.begin(), s_index.end(), _CNPLCM_CR_Basic_Freq_comparator); std::vector<int> perm(K); for (int k = 0; k < par->K; k++){ new2old[k] = s_index[k].second; } // new2old[a] == b <=> former b-th element is now a-th element. for (int k = 0; k < par->K; k++){ old2new[ new2old[k] ] = k; } CParams_NPLCM_CR_Basic_Freq *tmp = new CParams_NPLCM_CR_Basic_Freq(*par); //for (int i = 0; i < par->n; i++){ // tmp->zI[i] = old2new[ par->zI[i] ]; //} for (int m = 0; m < par->M; m++){ for (int k = 0; k < par->K; k++){ tmp->count_zIK[m][k] = par->count_zIK[m][ new2old[k] ]; } } for (int j = 0; j < par->J; j++){ for (int k = 0; k < par->K; k++){ tmp->lambdaJK[j][k] = par->lambdaJK[j][ new2old[k] ]; tmp->aux_JK2[j][k][0] = par->aux_JK2[j][ new2old[k] ][0]; tmp->aux_JK2[j][k][1] = par->aux_JK2[j][ new2old[k] ][1]; } } for (int k = 0; k < par->K; k++){ tmp->nuK[k] = par->nuK[new2old[k]]; tmp->log_nuK[k] = par->log_nuK[new2old[k]]; tmp->countK[k] = par->countK[new2old[k]]; tmp->count0K[k] = par->count0K[new2old[k]]; } //std::copy(tmp->zI, tmp->zI + par->n, par->zI); std::copy(tmp->count_zIK[0], tmp->count_zIK[0] + par->M * par->J, par->count_zIK[0]); std::copy(tmp->lambdaJK[0], tmp->lambdaJK[0] + par->J * par->K, par->lambdaJK[0]); std::copy(tmp->aux_JK2[0][0], tmp->aux_JK2[0][0] + par->J * par->K * 2, par->aux_JK2[0][0]); std::copy(tmp->nuK, tmp->nuK + par->K, par->nuK); std::copy(tmp->log_nuK, tmp->log_nuK + par->K, par->log_nuK); std::copy(tmp->countK, tmp->countK + par->K, par->countK); std::copy(tmp->count0K, tmp->count0K + par->K, par->count0K); delete tmp; }
void perm(int arr[], int l, int n, int k) { int i; if (l == k) { if (is_magic_square(arr)) print_square(arr); return; } for (i = l; i < n; i++) { swap(&arr[i], &arr[l]); perm(arr, l + 1, n, k); swap(&arr[i], &arr[l]); } }
/* lambda reduction (z=Z'*a, Qz=Z'*Q*Z=L'*diag(D)*L) (ref.[1]) ---------------*/ static void reduction(int n, double *L, double *D, double *Z) { int i,j,k; double del; j=n-2; k=n-2; while (j>=0) { if (j<=k) for (i=j+1;i<n;i++) gauss(n,L,Z,i,j); del=D[j]+L[j+1+j*n]*L[j+1+j*n]*D[j+1]; if (del+1E-6<D[j+1]) { /* compared considering numerical error */ perm(n,L,D,j,del,Z); k=j; j=n-2; } else j--; } }
void perm(char a[],int i,int n){ int j,temp; if(i==n){ printf("%s\n",a);k++;} else{ for(j=i;j<=n;j++) {k++; temp=a[j]; a[j]=a[i]; a[i]=temp; perm(a,i+1,n); temp=a[j]; a[j]=a[i]; a[i]=temp; } }}
void perm(int list[], int k, int m) { int i; if (k >= m) { for (i = 0; i < m; i++) { printf("%d ", list[i]); } printf("\n"); n++; } else { for (i = k; i < m; i++) { swap(&list[k], &list[i]); perm(list, k + 1, m); swap(&list[k], &list[i]); } } }
void tdmsPLS(double *x1, double *x2, int *m, double *epsilon, double *pval, double *sN, int *module1, int *module2, int *n1, int *n2, int *p, int *ncom, int *nperm, int *rescaleData, int *symmetrizeScores, int *rescaleScores){ int i,pvalnum; double psN; double *px1; double *px2; double *s1; double *s2; double *ps1; double *ps2; int *smod1; int *smod2; px1=malloc((*n1)*(*p)*sizeof(double)); px2=malloc((*n2)*(*p)*sizeof(double)); s1=malloc((*p)*(*p)*sizeof(double)); s2=malloc((*p)*(*p)*sizeof(double)); ps1=malloc((*p)*(*p)*sizeof(double)); ps2=malloc((*p)*(*p)*sizeof(double)); smod1=malloc((*p)*sizeof(int)); smod2=malloc((*p)*sizeof(int)); rplsnet(x1,s1,ncom,n1,p,rescaleData,symmetrizeScores,rescaleScores); rplsnet(x2,s2,ncom,n2,p,rescaleData,symmetrizeScores,rescaleScores); rgmd(s1,module1,m,epsilon,p); rgmd(s2,module2,m,epsilon,p); UnionIntersectionStat(module1,module2,sN,p); pvalnum=0; Rprintf("Starting permutation test:\n"); for (i=0;i<*nperm;i++){ Rprintf("permutation %i out of %i\n",i+1,*nperm); perm(x1,x2,px1,px2,n1,n2,p); rplsnet(px1,ps1,ncom,n1,p,rescaleData,symmetrizeScores,rescaleScores); rplsnet(px2,ps2,ncom,n2,p,rescaleData,symmetrizeScores,rescaleScores); rgmd(ps1,smod1,m,epsilon,p); rgmd(ps2,smod2,m,epsilon,p); UnionIntersectionStat(smod1,smod2,&psN,p); if (psN>=*sN) pvalnum++; } *pval=(0.0+pvalnum)/(*nperm); free(smod1); free(smod2); free(s1); free(s2); free(ps1); free(ps2); free(px1); free(px2); }
void tdcclassRR(double *x1, double *x2, int *f, int *nf, double *pval, double *dlt, int *n1, int *n2, int *p, double *lambda, int *nperm, int *rescaleData, int *symmetrizeScores, int *rescaleScores, int *distancetype){ int i,pvalnum; double pdlt; double *px1; double *px2; double *s1; double *s2; double *ps1; double *ps2; px1=malloc((*n1)*(*p)*sizeof(double)); px2=malloc((*n2)*(*p)*sizeof(double)); s1=malloc((*p)*(*p)*sizeof(double)); s2=malloc((*p)*(*p)*sizeof(double)); ps1=malloc((*p)*(*p)*sizeof(double)); ps2=malloc((*p)*(*p)*sizeof(double)); rrrnet(x1,s1,lambda,n1,p,rescaleData,symmetrizeScores,rescaleScores); rrrnet(x2,s2,lambda,n2,p,rescaleData,symmetrizeScores,rescaleScores); if (*distancetype==1) absDISTclassgenes(s1,s2,f,nf,dlt,p); else if (*distancetype==2) sqrDISTclassgenes(s1,s2,f,nf,dlt,p); (*dlt)/=*nf; (*dlt)/=(*nf)-1.0; pvalnum=0; Rprintf("Starting permutation test:\n"); for (i=0;i<*nperm;i++){ Rprintf("permutation %i out of %i\n",i+1,*nperm); perm(x1,x2,px1,px2,n1,n2,p); rrrnet(px1,ps1,lambda,n1,p,rescaleData,symmetrizeScores,rescaleScores); rrrnet(px2,ps2,lambda,n2,p,rescaleData,symmetrizeScores,rescaleScores); if (*distancetype==1) absDISTclassgenes(ps1,ps2,f,nf,&pdlt,p); else if (*distancetype==2) sqrDISTclassgenes(ps1,ps2,f,nf,&pdlt,p); pdlt/=*nf; pdlt/=(*nf)-1.0; if (pdlt>=*dlt) pvalnum++; } *pval=(0.0+pvalnum)/(*nperm); free(s1); free(s2); free(ps1); free(ps2); free(px1); free(px2); }
void ModifyMeshProperties::substituteMaterialID (GEOLIB::Polygon const& polygon, size_t old_mat_id, size_t new_mat_id) { MeshLib::ExtractMeshNodes mesh_node_extractor(_mesh); std::vector<size_t> mesh_node_ids; mesh_node_extractor.getMeshNodeIDsWithinPolygon(polygon, mesh_node_ids); const size_t n_mesh_node_ids(mesh_node_ids.size()); std::vector<size_t> perm(n_mesh_node_ids); // init permutation for sorting for (size_t k(0); k<n_mesh_node_ids; k++) perm[k] = k; // sort - since we want to use binary search Quicksort<size_t> (mesh_node_ids, 0, n_mesh_node_ids, perm); //#ifndef NDEBUG // std::ofstream test_out ("Points.gli"); // test_out << "#POINTS" << std::endl; // FileIO::OGSMeshIO mesh_io; // mesh_io.setMesh(_mesh); // mesh_io.writeMeshNodesAsGLIPnts(mesh_node_ids, test_out); // test_out << "#STOP" << std::endl; //#endif // get all nodes of the mesh const std::vector<MeshLib::CNode*>& mesh_nodes (_mesh->getNodeVector()); // get all elements of the mesh const std::vector<MeshLib::CElem*>& mesh_elements (_mesh->getElementVector()); for (size_t k(0); k<n_mesh_node_ids; k++) { std::vector<size_t> const& connected_element_ids (mesh_nodes[mesh_node_ids[k]]->getConnectedElementIDs()); for (size_t j(0); j<connected_element_ids.size(); j++) { if(mesh_elements[connected_element_ids[j]]->GetPatchIndex() == old_mat_id) { std::vector<size_t> connected_nodes; // check if all nodes of element are in the mesh_node_ids vector mesh_elements[connected_element_ids[j]]->getNodeIndices(connected_nodes); bool all_found(true); const size_t n_connected_nodes(connected_nodes.size()); for (size_t i(0); i<n_connected_nodes && all_found; i++) { if (searchElement(connected_nodes[i], 0, n_mesh_node_ids, mesh_node_ids) == std::numeric_limits<size_t>::max()) { all_found = false; } } if (all_found) { mesh_elements[connected_element_ids[j]]->setPatchIndex(new_mat_id); } } } } }
int main(){ int N = strlen(list); long F = factorial( N ); printf( "\n문자열 \'%s\'을 나열하는 경우의 수는 %d!(=%ld)입니다.\n", list, N, F ); printf( "그 모든 경우는 아래와 같습니다.\n\n"); perm( list, 0, N-1 ); getch(); return 0; }
void perm(int *A, int k, int n, int depth) { int i = 0; int B[ELEMENTS] = {0}; assign(B, A); for(i=k;i<n;i++) { swap(&A[k], &A[i]); if(k==depth) print(A, k+1); else perm(A, k+1, n, depth); assign(A, B); } }
int main(int argc,char *argv[]) { int n=2; char s[N]; w[n]='\0'; puts("This is a char permutation program!"); puts("Please input a string:"); scanf("%s",s); puts("Please input the char number of permuted:"); scanf("%d",&n); puts("The permuted chars are:"); perm(n,s); puts("\nPress any key to quit..."); getch(); return 0; }
void test_evaluator(const Interface& g) { typedef typename Interface::CellIterator CI; typedef typename CI ::FaceIterator FI; typedef typename CI ::Scalar Scalar; typedef Dune::SharedFortranMatrix FMat; std::cout << "Called test_evaluator()" << std::endl; std::vector<int> numf; numf.reserve(g.numberOfCells()); int max_nf = -1; for (CI c = g.cellbegin(); c != g.cellend(); ++c) { numf.push_back(0); int& nf = numf.back(); for (FI f = c->facebegin(); f != c->faceend(); ++f) ++nf; max_nf = std::max(max_nf, nf); } typedef int DummyClass; Dune::MimeticIPEvaluator<Interface, DummyClass> ip(max_nf); // Set dummy permeability K=diag(10,1,...,1,0.1). std::vector<Scalar> perm(dim * dim, Scalar(0.0)); Dune::SharedCMatrix K(dim, dim, &perm[0]); for (int i = 0; i < dim; ++i) K(i,i) = 1.0; K(0 ,0 ) *= 10.0; K(dim-1,dim-1) /= 10.0; // Storage for inverse ip. std::vector<Scalar> ip_store(max_nf * max_nf, Scalar(0.0)); // Loop grid whilst building (and outputing) the inverse IP matrix. int count = 0; for (CI c = g.cellbegin(); c != g.cellend(); ++c, ++count) { FMat Binv(numf[count], numf[count], &ip_store[0]); ip.evaluate(c, K, Binv); std::cout << count << " -> Binv = [\n" << Binv << "]\n"; } }
void myselect(char* str, int len, char* result, int start, int curr, int dest) { if (curr == dest) { // puts(result); perm(result, 3, 0); } else { int i; for (i = start; curr + len - i >= dest; ++i) { result[curr] = str[i]; myselect(str, len, result, i+1, curr+1, dest); } } }
void Graph::sort_edges(std::string order) { if (order == HILBERT) { VidType nv = (VidType)get_n_vertices(); LOG(INFO) << " Graph::nv = " << nv; VidType max_n = 2; while ( nv >>=1 ) { max_n <<= 1; } LOG(INFO) << " HilbertOrder::max_n = " << max_n; HilbertOrder::set_maxn(max_n); //HilbertOrder::set_maxn(MAX_BIT); //std::sort(edges.begin(), edges.end(), HilbertOrder()); // get permutation size_t ne = edges.size(); std::vector<int64_t> d(ne); for(size_t i = 0;i < ne;i ++) { d[i] = HilbertOrder::get_d(edges[i].src, edges[i].dst); } std::vector<size_t> perm(ne); for(size_t i = 0;i < ne;i ++) { perm[i] = i; } std::sort(perm.begin(), perm.end(), [&](const size_t & A, const size_t &B) { return d[A] < d[B]; }); d.resize(0); // sort size_t flag = 0; size_t cnt = 0; std::vector<Edge> edge_copy(edges); for(size_t i = 0;i < ne;i ++) { edges[i] = edge_copy[perm[i]]; } edge_copy.resize(0); } else if (order == DST ) {
void perm( char* list, int i, int n ){ /* index는 permutation의 경우 수를 계수하는 카운터 */ static int index = 1; int j; if( i == n ){ printf( "%3d: ", index++ ); for( j = 0; j <= n; j++ ) printf( "%c", list[j] ); printf( "\n" ); return; } { for( j = i; j <= n; j++ ){ /* SWAP( list[i], list[j] ); */ /* 위의 문장이 성립하려면 C++언어의 reference 를 이용하여야합니다 그러나 C언어에서는 위의 문장은 pass by value가 되므로 데이타의 교환이 이루어 지지않습니다. C언어에서 인덱스 i(start index)와 인덱스j의 데이타 위치를 교환하려면 아래와 같이 pass by reference 하기 위하여 pointer를 파라메타로 pass 합니다 */ SWAP( &list[i], &list[j] ); /* 재귀함수 호출 */ perm(list, i+1, n ); /* 앞서 교환된 인덱스i(start index)와 인덱스j의 데이타 위치를 다음의 위치교환을 위하여 원래 위치로 복귀시킵니다.*/ SWAP( &list[i], &list[j] ); /* 첫번째 문자가 바뀔 때마다 라인을 더 띄웁니다. */ if( i == 0 ) printf( "\n" ); } } }
void perm(int i) { int j,k,h; char t; int num[52]={0}; if(i<len) { for(j=i;j<=len;j++) { t=p[j]; for(k=j;k>i;k--) { p[k]=p[k-1]; } p[i]=t; if((p[i]>='a')&&(p[i]<='z')) { h= p[i]-'a'; num[h]++; } else { h= p[i]-'A'+26; num[h]++; } if(num[h]<=1){ perm(i+1); } for(k=i;k<j;k++) { p[k]=p[k+1]; } p[j]=t; } } else { for(j=1;j<=len;j++) { printf("%c",p[j]); } printf("\n"); } }
LLWearable* LLWearableList::createCopy(const LLWearable* old_wearable, const std::string& new_name) { lldebugs << "LLWearableList::createCopy()" << llendl; LLWearable *wearable = generateNewWearable(); wearable->copyDataFrom(old_wearable); LLPermissions perm(old_wearable->getPermissions()); perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true); wearable->setPermissions(perm); if (!new_name.empty()) wearable->setName(new_name); // Send to the dataserver wearable->saveNewAsset(); return wearable; }
MojErr MojDbPutHandler::configure(const MojObject& conf, MojDbReq& req) { LOG_TRACE("Entering function %s", __FUNCTION__); MojAssertWriteLocked(m_db->schemaLock()); // built-in permissions MojObject objects; if (conf.get(m_confProp, objects)) { MojObject::ConstArrayIterator end = objects.arrayEnd(); for (MojObject::ConstArrayIterator i = objects.arrayBegin(); i != end; ++i) { MojObject perm(*i); MojErr err = put(perm, req, false); MojErrCheck(err); } } return MojErrNone; }
void perm(int list[], int k, int m) { int i; if (k == m) { for (i = 0; i <= m; i++) perm_result[count][i] = list[i]; count++; } else { for(i = k; i <= m; i++) { swap(&list[k], &list[i]); perm(list, k+1, m); swap(&list[k], &list[i]); } } }
int perm(int list[],int k,int m) { if(k==m) { for(int i=0;i<=m;i++) cout<<list[i]; cout<<endl; n++; } else for(int i=k;i<=m;i++) { swap(list[k],list[i]); perm(list,k+1,m); swap(list[k],list[i]); } return 0; }
perm(int n, char *s) { char s1[N]; int i; if(n<1) printf("%s\n",w); /* 一个排列生成输出 */ else { strcpy(s1,s); /* 保存本层次可使用的字符 */ for(i=0;*(s1+i);i++) /* 依次选本层次可用字符 */ { *(w+n-1)=*(s1+i);/* 将选用字符填入正在生成的字符排列中 */ *(s1+i)=*s1; *s1=*(w+n-1); perm(n-1,s1+1); /* 递归 */ } } }
int main(int argc,char **argv) { user = argv[1]; if (!user) usage(); loguser = argv[2]; if (!loguser) usage(); dir = argv[3]; if (!dir) usage(); if (dir[0] != '/') usage(); myip = argv[4]; if (!myip) usage(); pw = getpwnam(loguser); if (!pw) strerr_die3x(111,FATAL,"unknown account ",loguser); init(dir,FATAL); makelog(loguser,pw->pw_uid,pw->pw_gid); makedir("env"); perm(02755); start("env/ROOT"); outs(dir); outs("/root\n"); finish(); perm(0644); start("env/IP"); outs(myip); outs("\n"); finish(); perm(0644); start("run"); outs("#!/bin/sh\nexec 2>&1\nexec chpst -U "); outs(user); outs(" -e ./env -d250000 "); outs(auto_home); outs("/bin/pickdns\n"); finish(); perm(0755); makedir("root"); perm(02755); start("root/data"); finish(); perm(0644); start("root/Makefile"); outs("data.cdb: data\n"); outs("\t"); outs(auto_home); outs("/bin/pickdns-data\n"); finish(); perm(0644); _exit(0); }
// static void LLPreview::onBtnCopyToInv(void* userdata) { LLPreview* self = (LLPreview*) userdata; LLInventoryItem *item = self->mAuxItem; if(item && item->getUUID().notNull()) { // Copy to inventory if (self->mNotecardInventoryID.notNull()) { copy_inventory_from_notecard(LLUUID::null, self->mNotecardObjectID, self->mNotecardInventoryID, item); } else if (self->mObjectUUID.notNull()) { // item is in in-world inventory LLViewerObject* object = gObjectList.findObject(self->mObjectUUID); LLPermissions perm(item->getPermissions()); if(object &&(perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID()) && perm.allowTransferTo(gAgent.getID()))) { // copy to default folder set_dad_inventory_item(item, LLUUID::null); object->moveInventory(LLUUID::null, item->getUUID()); } } else { LLPointer<LLInventoryCallback> cb = NULL; copy_inventory_item( gAgent.getID(), item->getPermissions().getOwner(), item->getUUID(), LLUUID::null, std::string(), cb); } } self->closeFloater(); }