Turn on thread page Beta
    Offline

    0
    ReputationRep:
    Those look like ten consecutive digits from e that add up to 49...

    If I'm correct, f(5) should be: **********.

    Edit:
    Heh, I was correct. I edited out the number I got, just in case I don't ruin someone else's fun.

    And to prove I did get it right: f(6) = 2952605956.
    • Thread Starter
    Offline

    0
    ReputationRep:
    yes yes well done you turnip - now go get a job at google :P
    Offline

    0
    ReputationRep:
    My programming skills let me down
    Offline

    0
    ReputationRep:
    (Original post by Willa)
    yes yes well done you turnip - now go get a job at google :P
    If only they'd hire a 16 year old...
    Offline

    0
    ReputationRep:
    Okay... I have a question. Obviously, if you want to solve the first puzzle, you have to check if the 10 digit number ($n) you obtained is divisible by $i (where 3<=$i<=sqrt($n)).

    I realise the easiest way to check this is using the modulus sign (%), and checking if the remainder is 0, i.e. if $n % $i = 0. If it is, then the number isn't prime.

    But when I tried this method, I ended up with a lot of numbers (including the one needed). So I took another approach: I used regex to match . (the decimal dot), and if for any division that dot wasn't there, the number wouldn't be prime.

    The second method worked perfectly. So my question is: how come the first one didn't?

    Here's my function:


    PHP Code:

    function checkprime($n) {
        
    $l substr($n,-1);
        if ((
    $l != 1) && ($l != 3) && ($l != 7) && ($l != 9)) { return 0; }
        
    $x floor(sqrt($n));
        for (
    $i=3;$i<=$x;$i++) {
            if (!
    preg_match("/\./",($n/$i))) { return 0; }
            
    /*The above is the line in question... 
            Why won't (!($n%$i)) or (($n%$i) == 0) work?*/
        
    }
        return 
    1;

    • Thread Starter
    Offline

    0
    ReputationRep:
    got to be something to do with the way the % operator works. I cant think what else.

    What numbers did the % method return? (list a few of them in order which they were found from the e number series)

    I'm assuming that the multiple answers given by % appeared BEFORE the actual answer. If the answer was the first returned value, well then there is no problem.
    Offline

    0
    ReputationRep:
    Here are the results I got using the % method:

    8281828459
    2845904523
    4590452353
    5235360287
    3536028747
    5360287471
    3602874713
    7135266249
    3526624977
    2662497757
    2497757247
    9775724709
    7757247093
    5724709369
    7247093699
    2470936999
    7093699959
    9369995957
    6999595749
    9595749669
    9574966967
    4966967627
    9669676277
    6762772407
    2772407663
    7240766303
    4076630353
    6630353547
    3035354759
    5354759457
    3547594571
    5475945713
    5945713821
    9457138217
    3821785251
    8525166427
    5166427427
    4274274663
    2742746639
    7427466391
    4274663919
    2746639193

    Btw, I used e=718281828459045235360287471352 66249775724709369995957496696762 77240766303535475945713821785251 6642742746639193.
    • Thread Starter
    Offline

    0
    ReputationRep:
    it's not being fussy about the spacing is it..... just try ($n % $i) just to be sure.
    Offline

    0
    ReputationRep:
    I tried that. I even tried setting $n % $i to another variable, but nothing worked.

    I think I just found a PHP bug?
    Offline

    0
    ReputationRep:
    lol "fantabulous" my butt :rolleyes:
    Offline

    0
    ReputationRep:
    can you please post the complete php code for me to check. I just did a dummy run using your checkprime function with modulus sign, and it worked fine!
    Offline

    0
    ReputationRep:
    PHP Code:
    $e "71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193";

    #There aren't supposed to be any spaces in $e... I don't know why this happens when I post. :P

    for ($n=0;$n<101;$n++) {
        
    $p substr($e,$n,10);
        if ((
    checkprime($p)) && ($p{0} != '0')) { echo "<b>MATCH</b> $p<br>"; }
    }

    function 
    checkprime($n) {
        
    $l substr($n,-1);
        if ((
    $l != 1) && ($l != 3) && ($l != 7) && ($l != 9)) { return 0; }
        
    $x floor(sqrt($n));
        for (
    $i=3;$i<=$x;$i++) {
            if (!
    preg_match("/\./",($n/$i))) { return 0; }
        }
        return 
    1;

 
 
 
Turn on thread page Beta
Updated: July 30, 2004

University open days

  • University of Warwick
    Undergraduate Open Days Undergraduate
    Sat, 20 Oct '18
  • University of Sheffield
    Undergraduate Open Days Undergraduate
    Sat, 20 Oct '18
  • Edge Hill University
    Faculty of Health and Social Care Undergraduate
    Sat, 20 Oct '18
Poll
Who is most responsible for your success at university
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

Equations

How to use LaTex

Writing equations the easy way

Equations

Best calculators for A level Maths

Tips on which model to get

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.