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

Home > Numbers
All digits distinct (Posted on 2018-12-12) Difficulty: 2 of 5
What is the highest prime number with no repeated digits?

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
late computer solution | Comment 3 of 5 |
Kudos to Charlie who noted the solution could not have 10 digits or it wouldn't be a prime (sod=45).  Silly me, my program ran for hours getting from 10 digits down to 9, but ultimately found the same answer as the others:   987,654,103.

(re-written to start from 9 digits):
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

for n in range(987654321,1,-2):
    s = str(n)
    if len(s) > len(set(s)):
        continue
    if isprime(n):
        print(n)
        break

  Posted by Larry on 2020-12-12 15:00:40
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 (3)
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