Rama chandranS

Greenhorn

Posts: 3

posted 5 years ago

Hi ,

I have this question from euler

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.

i don't know about this program

I need help in this ..

I have this question from euler

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.

i don't know about this program

I need help in this ..

posted 5 years ago

Welcome to CodeRanch!

So? What's the problem?

Let's start from the basics - What this problem has anything to do with Java? Is it that you want to write a program in Java? Because you are not mentioning it anywhere.

Further to that, this is NotACodeMill. Please share with us what you have tried, and where you are currently stuck/confused et-cetera. It would help other readers as well.

Rama chandranS wrote:Find the sum of the only eleven primes that are both truncatable from left to right and right to left.

So? What's the problem?

Let's start from the basics - What this problem has anything to do with Java? Is it that you want to write a program in Java? Because you are not mentioning it anywhere.

Further to that, this is NotACodeMill. Please share with us what you have tried, and where you are currently stuck/confused et-cetera. It would help other readers as well.

Regards,

Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)

posted 5 years ago

- 2

The fun of Project Euler is figuring out the solution yourself. It would be very boring if someone gave you the answer and you just fill it in on the website, it would not give you the satisfaction of solving the puzzle.

So, what's the problem - is there something that you don't understand about the puzzle? Did you write some code but you get stuck on it somewhere?

So, what's the problem - is there something that you don't understand about the puzzle? Did you write some code but you get stuck on it somewhere?

posted 5 years ago

Interestingly, this can be easily brute forced. I coded and solved the problem in about 20 minutes. Grab an old isPrime() method. Wrote a truncateLeft() method, as truncate right is incredibly easy. Wrote a check for truncate left primes. Wrote a check for truncate right primes. And did a brute force loop from 11 up (single digits are not truncate-able).

The question actually helps greatly here. It tells you that there are only eleven values, so you have an end point.

Henry

Rama chandranS wrote:

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 onlyeleven primesthat are both truncatable from left to right and right to left.

Interestingly, this can be easily brute forced. I coded and solved the problem in about 20 minutes. Grab an old isPrime() method. Wrote a truncateLeft() method, as truncate right is incredibly easy. Wrote a check for truncate left primes. Wrote a check for truncate right primes. And did a brute force loop from 11 up (single digits are not truncate-able).

The question actually helps greatly here. It tells you that there are only eleven values, so you have an end point.

Henry