# Math Is Fun Forum

Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

## #1 2024-05-13 01:37:13

Keep_Relentless
Member
From: Queensland, Australia
Registered: 2024-05-05
Posts: 58

### Project Euler Problems 7-9

The first 6 problems could be done with Excel. The next three are:

7. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? [Without looking it up.]

8. The four adjacent digits in the 1000-digit number that have the greatest product are 9*9*8*9 = 5832.

73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?

9. A Pythagorean triplet is a set of three natural numbers, a<b<c, for which, a^2 + b^2 = c^2. For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a*b*c.

"The most incomprehensible thing about the world is that it is comprehensible." -Albert Einstein.

Offline

## #2 2024-05-13 18:29:07

Keep_Relentless
Member
From: Queensland, Australia
Registered: 2024-05-05
Posts: 58

### Re: Project Euler Problems 7-9

A way to do problem 8 occurred to me. Let's give it a go.

Edit: Problem 8 done. Still no coding used.

Last edited by Keep_Relentless (2024-05-13 19:13:45)

"The most incomprehensible thing about the world is that it is comprehensible." -Albert Einstein.

Offline

## #3 2024-05-13 19:22:58

Keep_Relentless
Member
From: Queensland, Australia
Registered: 2024-05-05
Posts: 58

### Re: Project Euler Problems 7-9

Not sure whether problems 7 or 9 can be done on Excel in a reasonable amount of time.

"The most incomprehensible thing about the world is that it is comprehensible." -Albert Einstein.

Offline

## #4 2024-05-14 00:59:08

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

Keep_Relentless wrote:

A way to do problem 8 occurred to me. Let's give it a go.

Edit: Problem 8 done. Still no coding used.

Here's what I did:

Last edited by phrontister (Yesterday 13:32:09)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #5 2024-05-14 01:14:41

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

Hi Keep_Relentless;

I did #7 on Excel spreadsheet, but, after failing to come up with anything myself, cheated by using a UDF I found on the net that helped (but I won't reveal what/how, yet).

Last edited by phrontister (2024-05-14 01:25:37)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #6 2024-05-14 23:27:17

Keep_Relentless
Member
From: Queensland, Australia
Registered: 2024-05-05
Posts: 58

### Re: Project Euler Problems 7-9

These ones are trickier. It might be time to actually start coding.

"The most incomprehensible thing about the world is that it is comprehensible." -Albert Einstein.

Offline

## #7 2024-05-15 01:31:38

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

Keep_Relentless wrote:

These ones are trickier. It might be time to actually start coding.

I agree...and I solved #9 with a small BASIC code a couple of minutes ago.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #8 2024-05-15 10:47:54

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

Keep_Relentless wrote:

7. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? [Without looking it up.]

The Excel solution I mentioned in post #5 is a single column one that lists all the primes to the 10001st.

Mathematica has a 1-word function for returning just the 10001st prime.

My Liberty BASIC program came with a 'Sieve of Eratosthenes' module, which I adapted (clunkily) to return these options:
(a) just the 10001st prime, or
(b) all primes up to and including the 10001st.

Last edited by phrontister (2024-05-15 13:20:46)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #9 2024-05-15 13:55:54

Keep_Relentless
Member
From: Queensland, Australia
Registered: 2024-05-05
Posts: 58

### Re: Project Euler Problems 7-9

You have been busy!

I got problem 9 with a mixture of Mathematica and Excel. Is it considered cheating if you use Mathematica? You don't have to understand how the maths is done to use it. But you've got to start somewhere, it's useful incentive to learn to use Mathematica better. I will consider it as partial credit, haha, because I got formulas for a and c in terms of b and I have no idea how they were derived, but I was then able to hunt for answers systematically.

I will consider it full credit if you understand how the computer did it (or at least some theory that would let you arrive at the same conclusion), and partial credit otherwise. So I have labeled my excel for problem 9 "partial credit".

But by this criterion, we would be allowed to get the answer directly often, because there's often a simple iterative process. By this criterion, if I understand the sieve of eratosthenes, to cross out the multiples of every prime, I have a (laborious) method I could potentially carry out on pen and paper. So it is not really a mystery how the computer arrives at the answer.

I'm trying to justify myself in using M so we can go on to problems 10-12! I'll just go ahead and post them.

In case there's a way of explaining what M spit out regarding problem 9, I will share its result:

Last edited by Keep_Relentless (2024-05-15 14:15:49)

"The most incomprehensible thing about the world is that it is comprehensible." -Albert Einstein.

Offline

## #10 2024-05-16 00:05:04

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

Keep_Relentless wrote:

Is it considered cheating if you use Mathematica?

I hope not, coz I've used it on a couple of Project Euler problems posted years earlier here on MIF...and I didn't give it a moment's thought then!

However, it did cross my mind that M's 'Prime[10001]' solution was borderline cheating!

By this criterion, if I understand the sieve of eratosthenes, to cross out the multiples of every prime, I have a (laborious) method I could potentially carry out on pen and paper. So it is not really a mystery how the computer arrives at the answer.

Agreed.

Here's my clunky SofE code:

This is the Liberty BASIC code I referred to in post #8. LB costs \$\$, but the code also runs in Just BASIC v2.0, which is a scaled-down freeware version of LB.

I said previously that the code's 'clunky'. That was because I couldn't work out how to terminate iterations at the 10001st prime, and instead chose 'size=52370', which gives the solution that M gave! Btw, 52370*2 + 3 = that solution!

Edit: I forgot to say that the code will give just the 10001st prime. If you also want to print all the primes (which greatly slows down the operation), delete the 'Rem' tick preceding the two PRINT statements that have them, and place a Rem tick in front of the last PRINT statement.

Last edited by phrontister (2024-05-16 11:20:46)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #11 2024-05-16 01:55:00

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

Keep_Relentless wrote:

I got problem 9 with a mixture of Mathematica and Excel.

In case there's a way of explaining what M spit out regarding problem 9, I will share its result:

Your 500(2-√2)<b<500 is close to what I did, but I don't understand the other two. Sorry.

But here's how I solved it in M:

I didn't reinvent the wheel there...just used my BASIC strategy, which was my first solution method.

And here's my BASIC code:

Coded in Liberty BASIC, but also runs in Just BASIC (junior freeware version of LB).

I also worked out a not-too-tedious Excel solution (it looks more laborious than it is):

I hope those Excel instructions work for you!

Last edited by phrontister (2024-05-16 12:49:27)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #12 Yesterday 13:43:56

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,848

### Re: Project Euler Problems 7-9

phrontister wrote:
Keep_Relentless wrote:

A way to do problem 8 occurred to me. Let's give it a go.

Edit: Problem 8 done. Still no coding used.

Here's what I did:

This morning I worked out an M solution:

Last edited by phrontister (Yesterday 15:43:22)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline