I've been trying for a while now to find a solution for the problem in the title: determining if a number is perfect using a Turing Machine. I only had one class on the TM and while I did "get" how it works, this particular algorithm is being really hard for me to develop.
The algorithm I'm trying to implement on the TM is basically this (on C, returns true
iff n
is a perfect number):
int main(int n) {
int i=1, sum=0;
while ( n > i ) {
if ( n % i == 0 ) {
sum = sum + i;
}
i++;
}
return sum == n
}
The tough part for me right now is the while(n>i)
loop and the n%i
inside it.
Since I already have a program that does a%b
, I was trying to build the TM graph around it, but I'm not sure it's the best idea, specially since the b
on this case changes on every iteration. The software I'm using to simulate the TM is called JFlap.
The algorithm on table or graph form would be perfect.