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

You are not logged in.

#1 2017-01-02 11:43:36

Mathegocart
Member
Registered: 2012-04-29
Posts: 1,910

New Years Problem

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.
May bobbym have a wonderful time in the pearly gates of heaven.
He will be sorely missed.

Offline

#2 2017-01-02 13:05:00

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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

#3 2017-01-02 13:10:39

Mathegocart
Member
Registered: 2012-04-29
Posts: 1,910

Re: New Years Problem

bobbym wrote:

Hi;

You did that with M, I presume?

The integral of hope is reality.
May bobbym have a wonderful time in the pearly gates of heaven.
He will be sorely missed.

Offline

#4 2017-01-02 13:27:39

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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

#5 2017-01-13 01:19:32

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

Re: New Years Problem

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

#6 2017-01-13 05:58:26

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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

#7 2017-01-13 13:47:38

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

Re: New Years Problem

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

#8 2017-01-13 13:53:20

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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

#9 2017-01-13 14:12:34

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

Re: New Years Problem

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

#10 2017-01-13 14:19:23

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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

#11 2017-01-14 02:43:51

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

Re: New Years Problem

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]]``

"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 2017-01-14 02:54:06

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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

#13 2017-01-16 00:20:58

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

Re: New Years Problem

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

"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

#14 2017-01-16 02:44:53

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: New Years Problem

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