Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Feztaa
Results 1 to 6 of 6

Thread: Feztaa

  1. #1
    Guest

    Feztaa

    I saw your prime calculating program on CCAE. *Consider this one I made:

    Code:
    #!/usr/bin/env python
    
    import math, sys
    
    def isPrime(n, sqroot):
     *for x in xrange(2, sqroot+1):
     * *if n % x == 0:
     * * *return 0
    
     *return 1
    
    if len(sys.argv) < 2:
     *print "Usage: %s <Upper limit>" % sys.argv[0]
     *sys.exit(1)
    
    try:
     *number = int(sys.argv[1])
    except ValueError:
     *print "The limit must be an integer"
     *sys.exit(1)
    
    
    sqroot = math.sqrt(number)
    
    for i in xrange(1, number+1, 2):
     *if isPrime(i, sqroot): print i
    It seems to be much faster (not to mention more proper)

  2. #2

    Re: Feztaa

    TMTOWTDI, guy.

    My way demonstrates how to use an else clause in conjunction with a for loop (yes, that is a for...else statement in my script, no mistake).

  3. #3
    Guest

    Re: Feztaa

    For every iteration you calculate the square root. Check the difference:

    ./prime.py 10000 0.34s user 0.01s system 75% cpu 0.466 total
    ./feztaa.py 10000 5.45s user 0.04s system 55% cpu 9.896 total
    Kindda faster, heh?

  4. #4

    Re: Feztaa

    That's odd vince, seeing as mine doesn't take commandline arguments. It's interactive. Anyway, I'll look into it. It's not a priority right now.

  5. #5
    Guest

    Re: Feztaa

    No need to look, I already said what was the problem: you calculate the square root way too often.

  6. #6

    Re: Feztaa

    I have to read it to change it don't I? Or did you just expect me to delete mine and replace it with yours? How am I going to learn anything if I don't edit my own code? :

Similar Threads

  1. Feztaa?
    By GnuVince in forum General Chat
    Replies: 1
    Last Post: 11-01-2002, 09:03 PM
  2. Feztaa
    By gmoreno in forum General Chat
    Replies: 25
    Last Post: 09-04-2002, 01:06 PM
  3. Feztaa
    By GnuVince in forum General Chat
    Replies: 8
    Last Post: 08-03-2002, 12:43 AM
  4. Hey Feztaa...
    By inkedmn in forum Linux - Software, Applications & Programming
    Replies: 36
    Last Post: 03-06-2002, 01:33 AM
  5. Feztaa
    By gorn in forum General Chat
    Replies: 3
    Last Post: 11-22-2001, 05:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •