Thread: isPrime

  1. #16
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The isPrime N was significantly less than the N of the sieve of Eratosthenes. (my fault of course)

    So, isPrime gave me 0.570000, while the other remains 0.
    Last edited by std10093; 01-24-2013 at 11:12 AM. Reason: typo
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Salem View Post
    But it is in the initial assignment part (evaluated once), and not the condition or step parts (which are evaluated every time).
    Aw nuts. I'll use the fact that I have a cold at the moment as an excuse for missing that.
    I probably shouldn't do any programming today by the looks of it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #18
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    You had the intention to help, so no problem at all

    I hope you get better soon!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #19
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Laserlight - I still think that the book may be right; The wording is ambiguous to me. With regards to the clause -


    Does it mean that we may add "is" functions to our program?
    does it mean that we can add "is" functions to ctype.h?
    does it warn that "is" functions may be added by future standards to ctype.h?


    That part of the standard was put there for a reason - I think that the clause which you have sighted fits in better with the third line above, as functions probably shouldn't be added to ctype by everyone (with regard to keeping everything standard), and the clause you quoted does explicitly mentions ctype.h (which would discount the first option).


    I think that it is wise to remember that just because everyone does it, doesn't mean that everyone is correct. Also, just because a book suggests something, doesn't mean that it it correct. And lastly, just because we read the standard, it doesn't mean that we interpreted it correctly.


    I think that the book is most likely correct, because the argument makes sense: It's a good reason as to why it has been included into the standard. Why else would it be in the standards?


    This is the section 7.26 of C99 Draft standards:
    7.26 Future library directions
    #1
    The following names are grouped under individual headers for convenience. All external names described below are reserved no matter what headers are included by the program.


    7.26.1 Complex arithmetic <complex.h>
    #1
    The function names
    cerf cexpm1 clog2 cerfc clog10 clgamma * cexp2 clog1p ctgamma |
    and the same names suffixed with f or l are reserved for the functions with complex arguments and return values.

    7.26.2 Character handling <ctype.h>
    #1
    Function names that begin with either is or to, and a lowercase letter (possibly followed by any combination of digits, letters, and underscore) may be added to the declarations in the <ctype.h> header.

    ...
    Last edited by Click_here; 01-24-2013 at 05:53 PM. Reason: added quote, fixed font
    Fact - Beethoven wrote his first symphony in C

  5. #20
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by std10093 View Post
    Then, I will take a look at the paper Click_here talked about.
    you need to solve the question first!

    Enjoy
    Fact - Beethoven wrote his first symphony in C

  6. #21
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    I've found a second source and I'm afraid I'm going to have to concede that you were right, laserlight

    The prefix "is" is only reserved when immediately followed by a lowercase letter. (It was there in the standard all along)

    isprime would be a reserved name, but isPrime is fine.
    Fact - Beethoven wrote his first symphony in C

  7. #22
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Click_here View Post
    you need to solve the question first!

    Enjoy
    I just logged in to do this! Yes, I knew I had to solve it first tnx
    Quote Originally Posted by Click_here View Post
    I've found a second source and I'm afraid I'm going to have to concede that you were right, laserlight

    The prefix "is" is only reserved when immediately followed by a lowercase letter. (It was there in the standard all along)

    isprime would be a reserved name, but isPrime is fine.
    That's fine for me
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #23
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Click_here View Post
    If you solve this problem, you are given a short paper on prime number identification as a gift -
    Problem 7 - Project Euler

    [edit]
    Whoops - I meant Problem 10 - Project Euler
    But both correct answers will give you a different short paper on prime number identification as a gift
    Problem 10's paper is better!
    [/edit]

    Tell me how you go
    Question 7 solved in 5 minutes.
    Question 10 is not solved yet :/

    I think that the sum can't hold the result (due to precision). What type should it be?
    I printed the primes numbers until 2000000 and I got
    Code:
    ..
    ..
    1999891
    1999957
    1999969
    1999979
    1999993
    the sum must be a BIG number...
    Last edited by std10093; 01-25-2013 at 12:06 PM.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  9. #24
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    SOLVED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (now I will try out to find how I fixed it :P )
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  10. #25
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by std10093 View Post
    Question 7 solved in 5 minutes.
    Question 10 is not solved yet :/
    Five minutes? That is way too slow. You decided not to use the Sieve of Eratosthenes, then?

  11. #26
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Νο! I mean 5 minutes to write the code for the question

    For the history : The problem was on precision of a return value of a function.

    Performance :
    Question 7: 40ms

    Question 10 : 50 ms

    Thanks again everybody! I got very excited with all this!
    Last edited by std10093; 01-25-2013 at 01:12 PM.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed