Add files via upload
This commit is contained in:
		
							parent
							
								
									49382d9c82
								
							
						
					
					
						commit
						06c80fcd68
					
				
							
								
								
									
										9
									
								
								divisor 1.0/const.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								divisor 1.0/const.h
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | |||
| #ifndef __CONST_H_ | ||||
| #define __CONST_H_ | ||||
| 
 | ||||
| #define REJECT -1 | ||||
| #define ACCEPT -2 | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
							
								
								
									
										
											BIN
										
									
								
								divisor 1.0/main
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								divisor 1.0/main
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										48
									
								
								divisor 1.0/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								divisor 1.0/main.c
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,48 @@ | |||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include "turing.h" | ||||
| #include "states.h" | ||||
| #include "const.h" | ||||
| 
 | ||||
| #define REJECT -1 | ||||
| #define ACCEPT -2 | ||||
| 
 | ||||
| // gcc -g main.c turing.c states.c turing.h states.h const.h -o main
 | ||||
| 
 | ||||
| int main(){ | ||||
| 
 | ||||
| 	int List[] = {0,1,8,2,2,9}; | ||||
| 	int longitud=length(List); | ||||
| 	 | ||||
| 	fprintf(stdout,"\nEsta función acepta cuando n no divide a m."); | ||||
| 	 | ||||
| 	int state=0; | ||||
| 	int position=0; | ||||
| 	int symbol= List[position]; | ||||
| 	int movement =0; // undefined.
 | ||||
| 	int placeholder;	 | ||||
| 	 | ||||
| 
 | ||||
| 	while(state!=ACCEPT && state!=REJECT){ | ||||
| 		 | ||||
| 		print_linea(); | ||||
| 		print_variables(state,position,symbol, movement);		 | ||||
| 		print_lista(List, longitud, position); | ||||
| 
 | ||||
| 		fscanf(stdin,"\n%d", &placeholder); | ||||
| 
 | ||||
| 		carry_out_step(&symbol,&state,&movement); | ||||
| 		 | ||||
| 		List[position]=symbol; | ||||
| 		position = position +movement;	 | ||||
| 		symbol=List[position]; | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	print_linea(); | ||||
| 	print_variables(state,position,symbol, movement);		 | ||||
| 	print_lista(List, longitud, position); | ||||
| 
 | ||||
| 	 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										6
									
								
								divisor 1.0/states.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								divisor 1.0/states.h
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| #ifndef __STATES_H_ | ||||
| #define __STATES_H_ | ||||
| 
 | ||||
| void carry_out_step(int *symbol, int *state, int *movement); // This is the only function I'm going to need to use outside of states.c
 | ||||
| 
 | ||||
| #endif | ||||
							
								
								
									
										
											BIN
										
									
								
								divisor 1.0/states.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								divisor 1.0/states.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										86
									
								
								divisor 1.0/turing.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								divisor 1.0/turing.c
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,86 @@ | |||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include "turing.h" | ||||
| #include "const.h" | ||||
| 
 | ||||
| // Turing print defines functions that take a list, take a position in that list and print the list with a pointer to that position.
 | ||||
| // It prints this vertically
 | ||||
| 
 | ||||
| int length(int *List){ | ||||
| 	int i =0; | ||||
| 	 | ||||
| 	while (List[i]<9){ // Por cómo construimos nuestras listas.
 | ||||
| 		i=i+1; | ||||
| 	} | ||||
| 
 | ||||
| 	/*Anecdóticamente, el siguiente código da error.
 | ||||
| 	i=0;	 | ||||
| 	while (List[i]<=9){  | ||||
| 		i=i+1; | ||||
| 	}	 | ||||
| 	Y lo hace porque al asignar un trozo de memoria,  | ||||
| 	si la lista tiene, p.ej., longitud 6,  | ||||
| 	List[0] hasta Lista[5] son la lista de verdad,  | ||||
| 	pero Lista[6] <9, y la sigue contando. | ||||
| 	*/ | ||||
| 
 | ||||
| 	fprintf(stdout, "%d",i+1); | ||||
| 	return i+1; | ||||
| } | ||||
| 
 | ||||
| void print_lista(int*L, int length, int position){ | ||||
| 	if(L==NULL || length <= position){ | ||||
| 		fprintf(stdout, "\nError en prettyprint"); | ||||
| 	} | ||||
| 	else{ | ||||
| 		int i=0; | ||||
| 		char tabs[]="\t\t\t\t\t\t\t\0";	 | ||||
| 		for(i=0; i<length; i++){ | ||||
| 			if(i==position){ | ||||
| 				fprintf(stdout, "\n%s{",tabs); | ||||
| 			} | ||||
| 			else{ | ||||
| 				fprintf(stdout, "\n%s",tabs); | ||||
| 			} | ||||
| 
 | ||||
| 			if( L[i]==0){ | ||||
| 					fprintf(stdout, "T"); | ||||
| 
 | ||||
| 			} | ||||
| 
 | ||||
| 			else if(L[i]==8){ | ||||
| 					fprintf(stdout, "X"); | ||||
| 			} | ||||
| 
 | ||||
| 			else if(L[i]==9){ | ||||
| 					fprintf(stdout, "W"); | ||||
| 			} | ||||
| 
 | ||||
| 			else{ | ||||
| 					fprintf(stdout, "%d",L[i]); | ||||
| 			} | ||||
| 
 | ||||
| 			if(i==position){ | ||||
| 				fprintf(stdout, "}\n"); | ||||
| 			} | ||||
| 			else{ | ||||
| 				fprintf(stdout, "\n"); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void print_variables(int state, int position, int symbol,  int movement){ | ||||
| 	char tabs[]="\t\t\t\t\t\t\t\0";	 | ||||
| 	fprintf(stdout,"\n%sState =%d\n",tabs,state); | ||||
| 	fprintf(stdout,"\n%sPosition =%d\n",tabs,position); | ||||
| 	fprintf(stdout,"\n%sSymbol =%d\n",tabs,symbol); | ||||
| 	fprintf(stdout,"\n%sMovement =%d\n\n",tabs,movement); | ||||
| } | ||||
| 
 | ||||
| void print_linea(){ | ||||
| 	char tabs[]="\t\t\0";	 | ||||
| 	fprintf(stdout,"\n%s__________________________________________________________________________________________\n",tabs); | ||||
| } | ||||
							
								
								
									
										8
									
								
								divisor 1.0/turing.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								divisor 1.0/turing.h
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| #ifndef __CONST_H_ | ||||
| #define __CONST_H_ | ||||
| 
 | ||||
| void print_lista(int*L, int length, int position); | ||||
| void print_variables(int state, int position, int symbol,  int movement); | ||||
| int length(int *List); | ||||
| void print_linea(); | ||||
| #endif | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user