Mombu the Science Forum

Go Back   Mombu the Science Forum > Science > how to solve Google's puzzle using Maple?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 2nd July 16:07
alec mihailovs
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?



For example,

a:=convert(evalf[1000](exp(1)),string): for n from 3 do
p:=parse(a[n..(n+9)]); if isprime(p) then print(p); break fi od:

7427466391

Alec Mihailovs
http://math.tntech.edu/alec/
  Reply With Quote


 


2 2nd July 16:07
richard j. fateman
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?



Here's a version in macsyma:

fpprec:1000$
estring: substring(string(bfloat(%e),4)$
for i:1 thru 990 do
if primep(k:eval_string(substring(estring,i,i+9))) then return(k);

If Maple does not have convenient string-processing commands,
then that is probably easy to remedy. I don't think it should
be counted against this particular program.

RJF
  Reply With Quote
3 2nd July 16:07
alec mihailovs
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?


Also, it can be done "in one line", similar to Mathematica,

select(isprime,[seq(parse(sprintf("%a",evalf[200](exp(1)))[n..(n+9)]),
n=3..191)])[1];
7427466391

Alec Mihailovs
http://math.tntech.edu/alec/
  Reply With Quote
4 2nd July 16:07
israel
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?


|>news:200501051421.j05ELdOY044563@ns.mccme.ru...
|>> Puzzle is to find the first 10-digit prime number occurring in consecutive
|>> digits (i.e., the decimal expansion) of the e. Answer is known
|>> (7427466391), it was found using the following Mathematica code:
|>For example,
|>a:=convert(evalf[1000](exp(1)),string): for n from 3 do
|>p:=parse(a[n..(n+9)]); if isprime(p) then print(p); break fi od:

Another way, a bit more like the Mathematica code:

[n..(n+9)]),n=3..900))[1];

Of course, this is a lot less efficient than Alec's code, but still
takes only 0.751 seconds on my rather slow computer.


Robert Israel israel@math.ubc.ca
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia Vancouver, BC, Canada
  Reply With Quote
5 2nd July 16:07
carl devore
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?


The shortest efficient program that I came up with for this is

7427466391

It executes in 31 milliseconds in Maple 9.5.2 on a Pentium $ @ 1.6 GHz.

Both this program and the Mathematica program that you gave rely on the
fact that the answer will be found in the first 1000 digits. This is a
reasonable assumption since the probability that a random 10-digit number is prime is roughly

0.044

If you don't want to rely on that fact, then you can use this slightly longer program:


7427466391

IMO, this is a more satisfactory program; the first one and the
Mathematica one are cheating a bit.

This program takes 15 milliseconds on the same machine because it only
needs to compute the first 100 digits.
  Reply With Quote
6 2nd July 16:07
carl devore
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?


I meant the first 200 digits.
  Reply With Quote
7 4th July 10:46
joe riel
External User
 
Posts: 1
Default how to solve Google's puzzle using Maple?


Carl Devore <devore@math.udel.edu> writes:

While this works, I believe that there is a subtle flaw.
To get d digits of exp(1) you need to use evalf[d+2].
So you should have

S := cat("",op(1,evalf[d+2](exp(1))))[1..-3];

Note that the digits are not rounded, which is what is desired.


Joe
  Reply With Quote
Reply


Thread Tools
Display Modes




666