Jump to content
xisto Community

Anduril

Members
  • Content Count

    5
  • Joined

  • Last visited

Everything posted by Anduril

  1. That's a compressor i made during my university practical lessons on information theory, it's a text compressor, it's only usefull for texts containing only vocals, but it can easily be adapted for the whole alphabet ^^... Good luck with the comment translation!! (Catalan and Spanish...) #include <stdio.h>#include <math.h>#include <string.h>//En argv tenemos: (1)selector de compresion/descompresion (2)Tabla de frecuencias (3)Fichero de simbolos// (4)Fichero de salidaint treureDigitsCodificacio (int*,int*,FILE*,FILE*,int*,int*);void calcularAltBaix (int*,int*,int*,int,FILE*,FILE*,int*);int codifica(char *argv[]);int descodifica(char *argv[]);int treureDigitsDescodificacio (int*,int*,int*,FILE*,FILE*);void calcularSimbol(int*,int*,int*,int,int*,FILE*,FILE*);int main (int argc,char *argv[]){ int a; if (strcmp (argv[1],"-c") == 0) { a=codifica(argv); } else if (strcmp(argv[1],"-d") == 0) { a=descodifica(argv); }return a;} int treureDigitsCodificacio (int *al,int *ba,FILE *f_out, FILE *f_control,int *ca,int *uf) { //procedemos a eliminar las cifras comunes int cont=0; int i=0; while ((*al/10000) == (*ba/10000)) { fprintf(f_out,"%d",(*al/10000)); if(*uf!=0) { if(*ca==*al/10000)//Afegim 0s { for(i=0;i<*uf;i++) { fprintf(f_out,"%d",0); } i=0; *uf=0; } else//Afegim 9s { for(i=0;i<*uf;i++) { fprintf(f_out,"%d",9); } i=0; *uf=0; } } //printf("Afegirem %d al fitxer de sortida.\n",(*al/10000)); cont++; *al = ((*al-((*al/10000)*10000))*10)+9; *ba = ((*ba-((*ba/10000)*10000))*10); //printf("El nou Alt es %d.\nEl nou Baix es %d.\n",*al,*ba); fprintf (f_control,"Alt: %d, Baix: %d\n",*al,*ba); } if(((*al/10000)-(*ba/10000))==1)//Calculem underflow del nombre resultant { *ca=*al/10000; int at,bt; int segundo_a=(*al-(*al/10000)*10000)/1000; int segundo_b=(*ba-(*ba/10000)*10000)/1000; while(segundo_a == 0 && segundo_b == 9) { *uf= *uf +1; at=(*al-((*al/10000)*10000))-(segundo_a*1000); bt=(*ba-((*ba/10000)*10000))-(segundo_b*1000); *al=(((*al/10000)*10000)+at*10)+9; *ba=((*ba/10000)*10000)+(bt*10); segundo_a=(*al-(*al/10000)*10000)/1000; segundo_b=(*ba-(*ba/10000)*10000)/1000; } } return cont; } void calcularAltBaix (int *ra, int *al, int *ba,int N, FILE *f_simbol, FILE *f_control,int v_F[]) { int k; char sim; int alt = *al; int baix = *ba; int rang = *ra; sim=fgetc(f_simbol); if (sim == 'a') k=0; else if (sim == 'e') k=1; else if (sim == 'i') k=2; else if (sim == 'o') k=3; else if (sim == 'u') k=4; rang = alt - baix +1; alt = (baix + (rang * v_F[k])/ N) -1; if(k!=0) baix = (baix + (rang * v_F[k-1])/ N); //printf ("Com que el simbol es %c, k val: %d\n",sim, k); *al = alt; *ba = baix; *ra = rang; fprintf (f_control,"Caracter: %c, Alt: %d, Baix: %d\n",sim,*al,*ba); } int codifica(char *argv[]) { FILE *f_taula; FILE *f_simbol; FILE *f_out; FILE *f_control; f_taula = fopen (argv[2], "r"); f_simbol = fopen (argv[3], "r"); f_out = fopen (argv[4], "w"); f_control = fopen ("code.txt","w"); int alt = 99999; int baix = 0; int rang; char simbol; int cont=0; int underflow=0,control_alt; /*Obrir fitxers*/ simbol = fgetc(f_simbol); /*Comprovacio de validesa del fitxer d'entrada:*/ while (simbol!=EOF) { cont++; if (!(simbol == 'a' || simbol == 'e' || simbol == 'i' || simbol == 'o' || simbol == 'u')) { //printf ("Fitxer d'entrada erroni, simbol %c incorrecte\n",simbol); fclose(f_simbol); return -1; } simbol = fgetc(f_simbol); }//printf ("\n%d\n%d\n",alt,baix); rewind (f_simbol); //printf("Tenim un total de %d simbols per codificar.",cont); //Escrivim Capçalera fprintf(f_out,"TI2005-06\n"); fprintf(f_out,"%d\n",cont); fflush(f_out); /*Fi de la comprovacio*/ /*Tractament de la taula de freqĂÂźencies*/ int v_taula[5]; fscanf (f_taula,"%d",&v_taula[0]); int i = 1; while (!feof(f_taula)) { fscanf (f_taula,"%d",&v_taula[i]); i++; } /*Tractament del vector taula*/ int v_F [5]; //int v_P [5]; v_F [0]= v_taula [0]; for (i=1;i<5;i++) { v_F [i] = v_F [i-1] + v_taula [i]; } int N = v_F [4]; int caracters_codificats = 0; int ind; for(ind = 0; ind<cont; ind++) { //printf("\n----------------Simbol %d-------------------\n",(cont-ind)); calcularAltBaix (〉, &alt, &baix,N, f_simbol,f_control, v_F); //printf ("\n%d\n%d\n",alt,baix); //procedemos a eliminar las cifras comunescaracters_codificats = caracters_codificats + treureDigitsCodificacio(&alt,&baix,f_out,f_control,&control_alt,&underflow); } //Introduim al fitxer de sortida la xifra mes significativa de l'ultim baix. fprintf(f_out,"%d",(baix/10000)); //cal introduir-la al fitxer control? caracters_codificats++; //printf("Hem codificat %d caracters.",caracters_codificats); //printf("Tancant fitxers..."); fclose (f_taula); fclose (f_simbol); fclose (f_control); float RaoCompressioTeorica = (cont * 8) /( (caracters_codificats) * (log (10) / log (2))); printf ("Rao de Compressio Teorica: %f\n",RaoCompressioTeorica); fclose (f_out); return 0; }////////////////////////////////////////////////////////////////////////////////////////////// int descodifica(char *argv[]) { FILE *f_taula; FILE *f_out; FILE *f_control; FILE *f_desc; f_taula = fopen (argv[2], "r"); f_desc = fopen (argv[3], "r"); f_out = fopen (argv[4], "w"); f_control = fopen ("decode.txt","w"); int alt = 99999; int baix = 0; int valor=0; int valor_prov; char texto[10]; int num_caracteres; int i; /*Tractament de la taula de freqĂÂźencies*/ int v_taula[5]; fscanf (f_taula,"%d",&v_taula[0]); i = 1; while (!feof(f_taula)) { fscanf (f_taula,"%d",&v_taula[i]); i++; } /*Tractament del vector taula*/ int v_F [5]; //int v_P [5]; v_F [0]= v_taula [0]; printf("%d\n",v_F[0]); for (i=1;i<5;i++) { v_F [i] = v_F [i-1] + v_taula [i]; printf("%d\n",v_F[i]); } int N = v_F [4]; fscanf(f_desc,"%s",texto); if (strcmp (texto,"TI2005-06")==0) { fscanf(f_desc,"%d",&num_caracteres); printf("el num de vueltas es: %d\n",num_caracteres); } //inicialitzem valor valor_prov = getc(f_desc);//ens saltem el salt de linia valor = 0; for (i = 0; i<5 ; i++) { if ((valor_prov = getc(f_desc))!= -1) { valor = (valor*10)+(valor_prov -48); } else valor = (valor*10)+9; } printf("!!!!!!!!!!!!!!!!!!!!!!!!! ----------------> %d",valor); for (i=0;i<num_caracteres;i++) { //Calculem el simbol de sortida//recalculem alt,baix i valor calcularSimbol(&alt,&baix,&valor,N,v_F,f_control,f_out); //treiem els digits iguals. treureDigitsDescodificacio(&alt,&baix,&valor,f_control,f_desc); } fclose(f_desc); fclose(f_control); fclose(f_out); fclose(f_taula); return 0; }//////////////////////////////////////////////////////////// int treureDigitsDescodificacio (int *al,int *ba,int *val,FILE *f_control,FILE *f_desc) { //procedemos a eliminar las cifras comunes int cont=0; int prob = 0; while ((*al/10000) == (*ba/10000)) { //fprintf(f_out,"%d",(*al/10000)); //printf("Afegirem %d al fitxer de sortida.\n",(*al/10000)); cont++; *al = ((*al-((*al/10000)*10000))*10)+9; *ba = ((*ba-((*ba/10000)*10000))*10); if ((prob = getc(f_desc))!=-1) { *val = ((*val-((*val/10000)*10000))*10)+(prob-48); } else *val = ((*val-((*val/10000)*10000))*10)+9; fprintf(f_control,"El nou Alt es %d.\tEl nou Baix es %d.\t. Valor %d\n",*al,*ba,*val); } if(((*al/10000)-(*ba/10000))==1)//Calculem underflow del nombre resultant { int at,bt,vt; int segundo_a=(*al-(*al/10000)*10000)/1000; int segundo_b=(*ba-(*ba/10000)*10000)/1000; int segundo_v=(*val-(*val/10000)*10000)/1000; while(segundo_a == 0 && segundo_b == 9) { at=(*al-((*al/10000)*10000))-(segundo_a*1000); bt=(*ba-((*ba/10000)*10000))-(segundo_b*1000); vt=(*val-((*val/10000)*10000))-(segundo_v*1000); *al=(((*al/10000)*10000)+at*10)+9; *ba=((*ba/10000)*10000)+(bt*10); *val=((*val/10000)*10000)+(vt*10); if ((prob = getc(f_desc))!=-1) { *val =*val+(prob-48); } else *val =*val+9; segundo_a=(*al-(*al/10000)*10000)/1000; segundo_b=(*ba-(*ba/10000)*10000)/1000; segundo_v=(*val-(*val/10000)*10000)/1000; } } return cont; }//////////////////////////////////////////////////////////////////////////////// void calcularSimbol(int *al,int *ba,int *val,int N,int v_F[],FILE *f_control,FILE *f_out) { char simbol; int rang = *al-*ba+1; int i=0; while( !(((*val-*ba+1)*v_F[4]) < (v_F[i]*rang)) ) { i++; } if (i==0)simbol='a'; else if (i==1)simbol='e'; else if (i==2)simbol='i'; else if (i==3)simbol='o'; else if (i==4)simbol='u'; printf("------------%d",i); fprintf (f_control,"Alt: %d, Baix: %d, Valor: %d,Simbol: %c.\n",*al,*ba,*val,simbol); fprintf (f_out,"%c",simbol); //actualitzem alt i baix *al = (*ba + (rang * v_F[i])/ N) -1; if(i!=0) *ba = (*ba + (rang * v_F[i-1])/ N); } Oh... i almost forgot, it only works on Linux and Unix systems... Notice from miCRoSCoPiC^eaRthLinG: Once again, you lost a massive amount of credits, as you posted such a huge block of code without putting it in CODE or CODEBOX tags. Be VERY careful in future. Reducing Hosting credits worth 30 days
  2. That's an almost finished code for a sudoku solver in prolog, just missing some backtracking fixes... diferents(_,[]).diferents(0,[A|B]):-diferents(A,.diferents(A,[C|D]):-A\=C,A\=0,diferents(A,D).repetit([]).repetit([A|B]):-diferents(A,,repetit(.fer_ll(N,L):-fer_ll(N,[],L).fer_ll(0,L,L).fer_ll(N,LI,L):-N>0,N1 is N-1,fer_ll(N1,[N|LI],L).comptapos([],0).comptapos([A|B],N):-comptapos(B,N1),N is N1+1.ele_correctes([],_).ele_correctes(L):-comptapos(L,N),fer_ll(N,LP),append([0],LP,LP2),ele_correctes(L,LP2).ele_correctes([A|B],LP):-member(A,LP),ele_correctes(B,LP).verificasubllista([]).%verificasubllista(L):-ele_correctes(L),repetit(L).verificasubllista([A|B]):-ele_correctes(A),repetit(A),verificasubllista(.verificasudoku(L,N):-files(L,N,LF),columnes(L,N,LC),reg(L,N,LR),verificasubllista(LF),verificasubllista(LC),verificasubllista(LR).%verficasudoku([]).%verificasudoku([A|B]):-verificasubllista(A),verificasudoku(.files([],_,[]).files(LI,N,[X|Y]):-ll(LI,N,X,RX),files(RX,N,Y).ll([LI|RF],1,[LI],RF).ll([LI|RLI],N,[LI|RF],RL):-C is N-1,ll(RLI,C,RF,RL).columnes([],[],[]).columnes(A,N,L):-creallistes(A,N,A2),col(A2,L).col([A,A2|B],L):-afegirelements(A,A2,A3),col2(A3,B,L).col2(A3,[B1|RB],L):-afegirelements(A3,B1,C),col2(C,RB,L).col2(RES,[],RES).afegirelements([X|RX],[Y|RY],[CY|RCY]):-append(X,Y,CY),afegirelements(RX,RY,RCY).afegirelements([],[],[]).creallistes([],_,[]).creallistes(LI,N,[L|RL]):-ll(LI,N,Z,X),creasubllistes(Z,N,L),creallistes(X,N,RL).creasubllistes(_,0,[]).creasubllistes(LI,N,[X|Y]):-C is N-1,creasub2(LI,X,RX),creasubllistes(RX,C,Y).creasub2([LI|RE],[LI],RE).reg(LI,N,LF):-regions(LI,N,Z),col(Z,P),creasubreg(P,N,L),cridaappend(L,Q),aplana(Q,LF).creasubreg([],_,[]).creasubreg([X|Y],N,[Z|T]):-files(X,N,Z),creasubreg(Y,N,T).regions([],_,[]).regions(LI,N,[Z|Y]):-ll(LI,N,X,RX),sqrt(N,ARREL),files(X,ARREL,Z),regions(RX,N,Y).cridaappend([],[]).cridaappend([X,Y|T],[Z|F]):-append(X,Y,Z),cridaappend(T,F).aplana([X],X).completarLlista([],LA,LP,LR):-verificasubllista(LA),invertir(LA,LR).completarLlista(A,:-comptapos(A,N),fer_ll(N,LP),completarLlista(A,[],LP,.completarLlista([0|B],LA,LP,LF):-member(R,LP),completarLlista(B,[R|LA],LP,LF).completarLlista([A|B],LA,LP,LF):-A\=0,completarLlista(B,[A|LA],LP,LF).solucionarSudoku(A,N,LR):-files(A,N,,completaLlistes(B,LR),verificasudoku(A,N),appll(LR,R),mostraSudokuÂŽ.%!!!!!!!!!!!falta verificar sudokucompletaLlistes([],LA,LR):-invertir(LA,LR).completaLlistes(B,LR):-completaLlistes(B,[],LR).completaLlistes([A|B],LA,LR):-completarLlista(A,Z),completaLlistes(B,[Z|LA],LR).mostraSudoku(S):-display('\nSOLUCIĂ CORRECTA\n\n'),mostraSudoku(S,3,3,3).mostraSudoku([X|RX],0,_,_):-display('\n'),mostraSudoku([X|RX],3,3,3).mostraSudoku([X|RX],R,0,_):-display('\n'),R2 is R-1,mostraSudoku([X|RX],R2,3,3).mostraSudoku([X|RX],R,F,0):-display('\t'),F2 is F-1,mostraSudoku([X|RX],R,F2,3).mostraSudoku([],_,_,_).mostraSudoku([X|RX],R,F,C):-R>0,F>0,C>0,C2 is C-1,display(X),display(' '),mostraSudoku(RX,R,F,C2).%Sudoku de prova: [0,3,0,0,0,10,0,0,0,0,6,0,0,0,0,5,0,5,0,0,0,0,0,9,8,3,0,8,0,0,0,6,3,0,2,0,0,0,0,5,0,0,0,0,9,0,3,8,0,0,0,6,0,7,1,4,0,0,0,0,0,9,0,2,0,0,0,0,8,0,0,0,0,0,4,0,0,0,3,0]%Sudoku fĂ cil de prova: [8,3,2,5,9,1,6,7,4,4,9,6,3,8,7,2,5,1,5,7,1,2,6,4,9,8,3,1,8,5,7,4,6,3,9,2,2,6,7,9,5,3,4,1,8,9,4,3,8,1,2,7,6,5,7,1,4,6,3,8,5,2,9,3,2,9,1,7,5,8,4,6,6,5,8,4,2,9,1,3,7]% [8,3,2,5,9,1,6,0,0,4,9,6,3,8,7,2,5,0,5,7,1,2,0,0,0,8,3,1,8,0,7,4,6,0,0,2,2,6,7,9,5,3,4,1,8,9,4,3,0,1,2,7,6,0,0,0,4,6,3,8,5,0,9,3,2,9,1,7,5,0,4,6,6,5,8,4,2,9,1,3,7]invertir(L,LI):-invertir(L,[],LI).invertir([],L,L).invertir([X|RX],L,LI):-invertir(RX,[X|L],LI).appll(L,LF):-appll(L,[],LF).appll([A|C],LA,LF):-append(LA,A,Z),appll(C,Z,LF).appll([],LA,LA).files([],_,[]).files(LI,N,[X|Y]):-ll(LI,N,X,RX),files(RX,N,Y).ll([LI|RF],1,[LI],RF).ll([LI|RLI],N,[LI|RF],RL):-C is N-1,ll(RLI,C,RF,RL).columnes([],[],[]).columnes(A,N,L):-creallistes(A,N,A2),col(A2,L).col([A,A2|B],L):-afegirelements(A,A2,A3),col2(A3,B,L).col2(A3,[B1|RB],L):-afegirelements(A3,B1,C),col2(C,RB,L).col2(RES,[],RES).afegirelements([X|RX],[Y|RY],[CY|RCY]):-append(X,Y,CY),afegirelements(RX,RY,RCY).afegirelements([],[],[]).creallistes([],_,[]).creallistes(LI,N,[L|RL]):-ll(LI,N,Z,X),creasubllistes(Z,N,L),creallistes(X,N,RL).creasubllistes(_,0,[]).creasubllistes(LI,N,[X|Y]):-C is N-1,creasub2(LI,X,RX),creasubllistes(RX,C,Y).creasub2([LI|RE],[LI],RE).reg(LI,N,LF):-regions(LI,N,Z),col(Z,P),creasubreg(P,N,L),cridaappend(L,Q),aplana(Q,LF).creasubreg([],_,[]).creasubreg([X|Y],N,[Z|T]):-files(X,N,Z),creasubreg(Y,N,T).regions([],_,[]).regions(LI,N,[Z|Y]):-ll(LI,N,X,RX),sqrt(N,ARREL),files(X,ARREL,Z),regions(RX,N,Y).cridaappend([],[]).cridaappend([X,Y|T],[Z|F]):-append(X,Y,Z),cridaappend(T,F).aplana([X],X). Maybe you'll nedd to translate predicate names from spanish to english, also some of the predicates are in Catalan... sry ^^ Notice from miCRoSCoPiC^eaRthLinG: When you publish such large blocks of code, make sure you include them between CODE or CODEBOX tags. Failure to do so will cause your credits to be adjusted - which means you might loose all the credits for such a post. Secondly - such a code is quite useless, unless you clearly explain at each step - what exactly is happening. That is a MUST for posts like this - coz without such explanations, again, the code alone is quite useless. It's like leaving others groping in the dark trying to figure it all by themselves - specially for newbies. Since, you're new to this board, you'll get off without a warning this time. But our credits system is heavily dependent on proper usage of the BBCode tags. Hence, I'm forced to adjust the credits - Reducing Hosting credits worth 18 days.
  3. Hi there!!Well, i only wanted to know if it was a good choice to use swift 3d for my flash 3d effects or you would advice me to use some other applications.I'm asking this because i've been having some problems with this app, as long as i don't have a dygitalizer board and i hav to design with my mouse... I know it's not the best way to do it, but my resources are limitted and i'm an amateur designer ^^.Well my problems are related directly with modeling, so i would be thankfull if you could tell me any good applications for easy-modelling, because swift 3d makes it easy for text effects, but becomes quite difficult for 3d objects.Furthermore, it's object library is not very large.Ok, please, read this and tell me what you'd use in my case or just what you are using right now and why ^^.Thank you all in advance!
  4. Well, it depends on how you have implemented the on site navigation; i mean: -If the web you designed loads the 100% of it's content when a user just visits it, then it's an awful design and you should start thinking on other ways to manage your info weight... -If the design wisely distributes the info on independent loading sections, then it's OK, in fact, a flash web could include as much info as you desired if it was loaded in pieces. -If you are looking for help on how to manage this weight problen, try visiting http://www.flashdeveloper.nl//?gtnjs=1
  5. well, i think it does, at least in Spain, but, if i'm not wrong, you can use up to 30 seconds of any copyrighted song or movie without violating any law...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.