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

Home > Numbers
Four-Digit Number (Posted on 2003-04-26) Difficulty: 4 of 5
Find a four-digit number with four different digits, that is equal to the number formed by its digits in descending order minus the number formed by its digits in ascending order.

See The Solution Submitted by Ravi Raja    
Rating: 3.1667 (6 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re: My solution -- exhausive search uniqueness shown | Comment 3 of 15 |
(In reply to My solution by Gamer)

Proof of uniqueness of the solution is obtained by the following program that looks at all numbers formed with four different digits in ascending sequence and subtracting that from it's reverse and sees if the result has the same four digits. It includes the possibility that the leading digit is zero. Only 7641 - 1467 = 6174 is found by the program.

FOR i = 0 TO 6
  FOR j = i + 1 TO 7
    FOR k = j + 1 TO 8
      FOR l = k + 1 TO 9
        diff = l * 1000 + k * 100 + j * 10 + i - (i * 1000 + j * 100 + k * 10 + l)
        s$ = LTRIM$(STR$(diff))
        IF LEN(s$) < 4 THEN
          s$ = RIGHT$("0000" + s$, 4)
        END IF
        s1$ = LTRIM$(STR$(l * 1000 + k * 100 + j * 10 + i))
        DO
         ix = INSTR(s1$, LEFT$(s$, 1))
         IF ix = 0 THEN EXIT DO
         s1$ = LEFT$(s1$, ix - 1) + MID$(s1$, ix + 1)
         s$ = MID$(s$, 2)
        LOOP UNTIL s$ = ""
        IF s$ = "" THEN
          d = l * 1000 + k * 100 + j * 10 + i
          a = i * 1000 + j * 100 + k * 10 + l
          PRINT d; "-"; a; "="; d - a
        END IF
      NEXT
    NEXT
  NEXT
NEXT

  Posted by Charlie on 2003-04-26 09:17:17

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