1. Getting a different answer to the one expected/published

Truncatable primes - The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3. Find the sum of the only eleven primes that are both truncatable from left to right and right to left. NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.

The following is my effort to sole this. the answer i get is 573 which makes sense until you consider there is only supposed to be 11 and the example given is bigger than the 11 i found

Code:
```#include <stdio.h>
#include <stdlib.h>

#define Countto 1000000

int FindMod( int *, int );
int CheckPrime( int *, int );
int Truncatable( int *, int, int, int );

int main()
{
int NumSieve[Countto] = { 0 };
int Sum = 0, Counter = 0;

for (int i = 11; i < Countto; i += 2)
{
int Mod = 10, Limit = FindMod( &Mod, i );

if ( CheckPrime( NumSieve, i % Mod) )
if ( Truncatable(NumSieve, Mod, Limit, i ) )
{
printf("%d\n", i);
Sum += i;
Counter++;
}
if ( Counter == 11 )
break;
}

printf("Sum of the 11 truncatable primes is: %d\n", Sum);
return 0;
}

int FindMod( int *Mod, int Num )
{
int Counter = 0;

while ( Num % *Mod < Num )
{
*Mod *= 10;
Counter++;
}

return Counter;
}

{
for ( int i = 4; i < Countto; i += 2 )
Primes[i] = 1;

for ( int i = 3; i < 1000; i += 2 )
{
if ( Primes[i] == 0 )
for ( int j = i * 2; j < Countto; j += i)
Primes[j] = 1;
}
}

int CheckPrime( int *Primes, int Index )
{
return Primes[Index] == 0; //Index is prime
}

int Truncatable( int *NumSieve, int Mod, int Limit, int i )
{

int TruncNum[Limit];

for ( int j = 0; j < Limit; j++ )
{
Mod /= 10;
if ( !CheckPrime( NumSieve, i % Mod ) )
return 0;

TruncNum[j] = i % Mod;
}

for ( int j = Limit - 1; j >= 0; j-- )
{
if ( !CheckPrime( NumSieve, ( i - TruncNum[j] ) / Mod  ) )
return 0;

Mod *= 10;
}

return 1;
}```
where am i going wrong

2. Originally Posted by cooper1200
Truncatable primes - The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3. Find the sum of the only eleven primes that are both truncatable from left to right and right to left. NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.

The following is my effort to sole this. the answer i get is 573 which makes sense until you consider there is only supposed to be 11 and the example given is bigger than the 11 i found

where am i going wrong
191 * 3 = 573

Tim S.

3. ummmm 573 is the sum of the truncatable primes i found

the truncatable primes are
Code:
```11
13
17
23
31
37
53
71
73
113
131```
if you add them up you get 573

4. Originally Posted by cooper1200
ummmm 573 is the sum of the truncatable primes i found

the truncatable primes are
Code:
```11
13
17
23
31
37
53
71
73
113
131```
if you add them up you get 573
1 is defined as not prime!

Tim S.

5. so is 3 and 7 but they count those on 3795

6. Originally Posted by cooper1200
so is 3 and 7 but they count those on 3795
Wow, you are truly ignorant about math.

Goodbye.

Tim S.

7. Originally Posted by stahta01
Wow, you are truly ignorant about math.

Goodbye.

Tim S.
Prime number - Wikipedia

8. Originally Posted by stahta01
Wow, you are truly ignorant about math.

Goodbye.

Tim S.
nothing to do with mathS i can speak and understand plain English

9. Originally Posted by cooper1200
nothing to do with mathS i can speak and understand plain English
You do understand that 2 is the smallest prime number, correct?

If you do not understand that then this problem is not one you can solve till you understand more about prime numbers.

Therefore all the numbers that start and end with "1" do not count as valid for this problem. I have no idea if the ones with "1" in the middle count as valid.

Tim S.

10. Code:
```#include <stdio.h>
#include <stdlib.h>

int isprime(int n) {
if (n < 2) return 0;
if (n % 2 == 0) return n == 2;
for (int d = 3; d * d <= n; d += 2)
if (n % d == 0) return 0;
return 1;
}

int is_truncatable_prime(int n) {
if (!isprime(n)) return 0;
for (int m = n / 10; m; m /= 10)
if (!isprime(m)) return 0;
char s[20];
int len = sprintf(s, "%d", n);
for (int i = 1; i < len; ++i)
if (!isprime(atoi(s + i))) return 0;
return 1;
}

int main () {
int sum = 0;
for (int p = 11, i = 0; i < 11; p += 2)
if (is_truncatable_prime(p)) {
printf("%6d\n", p);
sum += p;
++i;
}
printf("======\n%6d\n", sum);
return 0;
}
/*
Output:
23
37
53
73
313
317
373
797
3137
3797
739397
======
748317
*/```

11. ok am i understanding this correctly? in the function is_truncatable_prime you test if the number passed is not prime ie if a number is prime the if statement fails and the function continues. However, function is_prime tests weather the number is even or not and if it is returns 2. Does this not cause the !is_prime to fail and therefore allow even numbers through.

12. is_prime never returns 2. It returns the value of n == 2, i.e., it returns 1 if n is 2 and 0 if it isn't.
Basically, if a number is divisible by 2 then it is only prime if it actually is 2.

13. that's it im going to the ophthalmologist

14. Originally Posted by cooper1200
that's it im going to the ophthalmologist
Just look at my previous post.