diff --git a/divisor 1.0/const.h b/divisor 1.0/const.h new file mode 100644 index 0000000..b0babc6 --- /dev/null +++ b/divisor 1.0/const.h @@ -0,0 +1,9 @@ +#ifndef __CONST_H_ +#define __CONST_H_ + +#define REJECT -1 +#define ACCEPT -2 + +#endif + + diff --git a/divisor 1.0/main b/divisor 1.0/main new file mode 100644 index 0000000..5cc81b3 Binary files /dev/null and b/divisor 1.0/main differ diff --git a/divisor 1.0/main.c b/divisor 1.0/main.c new file mode 100644 index 0000000..fb1ac54 --- /dev/null +++ b/divisor 1.0/main.c @@ -0,0 +1,48 @@ +#include +#include +#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); + + + +} diff --git a/divisor 1.0/states.h b/divisor 1.0/states.h new file mode 100644 index 0000000..625b918 --- /dev/null +++ b/divisor 1.0/states.h @@ -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 diff --git a/divisor 1.0/states.o b/divisor 1.0/states.o new file mode 100644 index 0000000..1e33186 Binary files /dev/null and b/divisor 1.0/states.o differ diff --git a/divisor 1.0/turing.c b/divisor 1.0/turing.c new file mode 100644 index 0000000..1c5535f --- /dev/null +++ b/divisor 1.0/turing.c @@ -0,0 +1,86 @@ +#include +#include +#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