You are not logged in.
Pages: 1
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
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
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
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
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
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
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
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
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
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
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
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
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
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