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

Home > Numbers
5 Digit Number IV (Posted on 2023-04-08) Difficulty: 3 of 5
  1. N is a positive integer having exactly 5 distinct digits from 1 to 9 inclusively.
  2. Two of the digits of N are perfect squares.
  3. Two of the digits of N are prime numbers.
  4. One of the digits in N is neither a prime number nor a perfect square.
  5. Numerical value of third digit from the left is precisely twice that of the fifth digit.
  6. The fourth digit from the left is precisely 6 greater than the second digit.
  7. Reading from the left, the last digit is precisely 3 less than the first digit.
Determine the value of N.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Solution Comment 1 of 1
Of the 6 constraints, the last three narrow it down to just 6 possible values for the first digit and three possible values for the second digit.  The last 3 digits are fully determined by the first two.  So there are only 36 possible solutions, before even considering the first three constraints.

The solution is unique:
73894

--------------
squares = [1,4,9]
primes = [2,3,5,7]
neither = [6,8]

for a in range(4,10):
    for b in range(1,4):
        d = b+6
        e = a-3
        c = 2*e
        digits = [a,b,c,d,e]
        if len(digits) != len(set(digits)):
            continue
        s_count = 0
        for i in digits:
            if i in squares:
                s_count += 1
        if s_count != 2:
            continue
        
        p_count = 0
        for i in digits:
            if i in primes:
                p_count += 1
        if p_count != 2:
            continue

        n_count = 0
        for i in digits:
            if i in neither:
                n_count += 1
        if n_count != 1:
            continue
        stringDigits = [str(i) for i in digits]
        print(int(''.join(stringDigits)))


  Posted by Larry on 2023-04-08 10:50:19
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 (11)
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