Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
isprime function
#5
Quote:
Code:
#!/usr/bin/env python
def isprime(n):
    if n > 10:
        for x in range(2, 11): if n%x == 0: return False
        else: return True
    if n <= 10: return False if n in [1, 4, 6, 8, 9, 10] else True

Defeated by:
Code:
if isprime(x) and x > 11: isprime(x**x)

For example:
Code:
if isprime(13) and x > 11: # Will return true, as 13 is a prime and is larger than 10.
    isprime(13**13) # As 13 is not in the check list, this number will be found to be a prime, even though it clearly is not.
Reply


Messages In This Thread
isprime function - by nevets04 - 02-23-2010, 01:54 PM
RE: isprime function - by uber1337 - 02-23-2010, 06:46 PM
RE: isprime function - by Fallen - 04-05-2010, 06:15 PM
RE: isprime function - by uber1337 - 04-06-2010, 12:03 PM
RE: isprime function - by symetrik - 04-18-2010, 11:08 AM
RE: isprime function - by wat - 05-05-2010, 05:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic filter function uber1337 1 968 08-13-2010, 10:59 AM
Last Post: xerotic

Forum Jump:


Users browsing this thread: 1 Guest(s)