Results 1 to 6 of 6

Math Help - Maple - Finding numbers on pi

  1. #1
    Member
    Joined
    Jul 2009
    Posts
    168

    Maple - Finding numbers on pi

    Hello!

    I need to find out how many strings of 3 same numbers or more exist on Pi's first 10,000 digits. So I wrote this on Maple:

    p := evalf[210](Pi);
    cnt := 0;
    for i to 210 do
    a1 := floor(p);
    if a1 = floor((p-a1)*10) then
    if a1 = floor(100*(p-a1-0.1*a1)) then
    cnt := cnt+1;
    while a1 = floor(1000*(p-a1-0.1*a1-0.01*a1)) do
    cnt := cnt+1;
    p := 10*(p-a1) ;
    end do;
    end if;
    end if;
    p := 10*(p-a1);
    end do;
    cnt

    (This one is up to 210 digits, just wanted to check).

    When I run, it keeps calculating, but when I stopped (after about 10 minutes) cnt was 70571756... Where is my mistake?

    Thank you very much
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member Deadstar's Avatar
    Joined
    Oct 2007
    Posts
    722
    Not quite sure what your code is doing and if you could explain it a bit I might be able to advise you but here is one I wrote. It's very inefficient but I'm discussing it with some folk over on a different forum so may post up a better one later.

    A := NULL:
    a := NULL:
    for k from 0 to 9997 do
    a := [floor(evalf[10000]((10^k)*Pi)) mod 10,
    floor(evalf[10000]((10^(k+1))*Pi)) mod 10,
    floor(evalf[10000]((10^(k+2))*Pi)) mod 10]:
    if a[1]=a[2] and a[1]=a[3] then
    A := A+1:
    k := k+3
    end if:
    end do:
    A;
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Jul 2009
    Posts
    168
    Thank you, it's a very nice way to solve it.

    I only have two problems now:

    *I can't use mod with irrational numbers (not also modp).
    *It should count how many strings of 3 or more. So for instance, if there's a 6 string (low possibilities, but still) - it should recognize it as one.

    Thanks for your help
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member Deadstar's Avatar
    Joined
    Oct 2007
    Posts
    722
    Quote Originally Posted by adam63 View Post
    Thank you, it's a very nice way to solve it.

    I only have two problems now:

    *I can't use mod with irrational numbers (not also modp).
    *It should count how many strings of 3 or more. So for instance, if there's a 6 string (low possibilities, but still) - it should recognize it as one.

    Thanks for your help
    Yeah, it takes the floor first so you can use mod. Have you tried it? It seems to work but I don't know how many strings there should be...

    If will only recognize a larger string if there is a 7 string one. (which is what the k := k+3 does). As I said I should be posting an updated version hopefully soon.

    Have a look at the StringTools package as well.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Member
    Joined
    Jul 2009
    Posts
    168
    Quote Originally Posted by Deadstar View Post
    Yeah, it takes the floor first so you can use mod. Have you tried it? It seems to work but I don't know how many strings there should be...

    If will only recognize a larger string if there is a 7 string one. (which is what the k := k+3 does). As I said I should be posting an updated version hopefully soon.

    Have a look at the StringTools package as well.
    Oh, I see, I thought the 'floor' takes place after the mod... now it's just fine.

    Thanks
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Super Member Deadstar's Avatar
    Joined
    Oct 2007
    Posts
    722
    s:=convert(trunc(evalf(Pi*10^10000,10003)), string):
    with(StringTools):
    R:= [SearchAll([seq(cat(i,i,i),i="0".."9")],s)]:

    nops(R);


    Not 100% sure how this code works but was given it by someone else.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: November 30th 2011, 02:25 PM
  2. Replies: 1
    Last Post: September 27th 2010, 03:14 PM
  3. Maple 10: solve() and complex numbers
    Posted in the Math Software Forum
    Replies: 1
    Last Post: August 3rd 2009, 07:17 AM
  4. Complex Numbers in 3D/ Maple for control
    Posted in the Math Software Forum
    Replies: 2
    Last Post: May 13th 2009, 08:05 AM
  5. Maple - finding a sequence
    Posted in the Math Software Forum
    Replies: 0
    Last Post: September 27th 2008, 10:37 AM

Search Tags


/mathhelpforum @mathhelpforum