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

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**Mathegocart****Member**- Registered: 2012-04-29
- Posts: 1,848

1. For the set of positive integers from [1, 10000], find the sum of all values of x such that x^2 + 27 and x + 3 are prime.

*Last edited by Mathegocart (2017-01-02 12:41:30)*

The integral of hope is reality.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

Hi;

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**Mathegocart****Member**- Registered: 2012-04-29
- Posts: 1,848

bobbym wrote:

Hi;

You did that with M, I presume?

The integral of hope is reality.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

Is there anything better?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

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

Hi;

I got the same answer as Bobby's, also with M.

There are 236 solutions to "all values of x such that x^2 + 27 and x + 3 are prime".

*Last edited by phrontister (2017-01-13 01:35:47)*

"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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

Very good work!

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

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

The right tool for the job!

I tried using Table instead of For etc, but couldn't see how.

"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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

Hi;

For a functional approach:

`Select[Range[10000], PrimeQ[#^2 + 27] && PrimeQ[# + 3] &] // Total`

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

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

Yes, the functional approach is what I was trying for.

Just having a go now with your code to get it to return the x count as well. That would be via Length, I guess.

...but lunch first.

...and may have to go out soon after.

"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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

Yes, Length is the command that will tell you how long that list is. You can try this.

```
Select[Range[10000], PrimeQ[#^2 + 27] && PrimeQ[# + 3] &];
Total[%]
Length[%%]
```

Have a good lunch.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

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

Very yummy lunch, thanks, followed late afternoon by even yummier birthday party food!

That's a neat trick, using %n to choose specific output lines! It does away with introducing another variable, unlike the following variations of your code...

Mine:

```
p=Select[Range[10000],PrimeQ[#^2+27]&&PrimeQ[#+3]&];
Total[p]
Length[p]
```

SE1:

`p=Select[Range[10000],PrimeQ[#^2+27]&&PrimeQ[#+3]&];#[p]&/@{Total,Length}`

SE2:

`p=Select[Range[10000],PrimeQ[#^2+27]&&PrimeQ[#+3]&];Through[{Total,Length}[p]]`

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

There is undoubtedly a much shorter way to do this.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

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

But I thought your code was about as short as it could get!

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 107,751

That would be a piece of luck. M exposes all my weaknesses.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

Pages: **1**