All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Extreme Eleven Exercise (Posted on 2010-01-21) Difficulty: 3 of 5
N is an 11-digit base ten prime number N (with no leading zero) with the proviso that N contains each of the digits from 0 to 9 at least once.

Determine the respective minimum and maximum value of N.

See The Solution Submitted by K Sengupta    
Rating: 4.0000 (3 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer solution Comment 5 of 5 |
The smallest is 10123457689
The largest is   98876532401
------------
def isprime(n):
    '''check if integer n is a prime'''
    n = abs(int(n))
    if n < 2:
        return False
    if n == 2: 
        return True    
    if not n & 1: 
        return False
    for x in range(3, int(n**0.5)+1, 2):
        if n % x == 0:
            return False
    return True

bigsmall = '98876543210'
smallbig = '01123456789'
from itertools import permutations

for perm in permutations(smallbig):
    if perm[0] == '0':
        continue
    n = (int(''.join(perm)))
    if isprime(n):
        print('The smallest is',n)
        break

for perm in permutations(bigsmall):
    n = (int(''.join(perm)))
    if isprime(n):
        print('The largest is',n)
        break

  Posted by Larry on 2023-06-12 17:56:22
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information