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

Home > Numbers
Permutation List 3 (Posted on 2023-07-25) Difficulty: 3 of 5
If all the 40320 (base 10) permutations of 12345678 in the hexadadecimal (base 16) representation are put in numerical order, what is the 20230th (base ten) pemutation?

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 3
Solved two ways.
First way, relying on itertools to be in order:
output:  51268473 1361478771
HEX: 51268473  =  DEC:1361478771

Confirmed by running the second program which prints out:
51268473 1361478771
51268473 1361478771

-------------------
def base2base(n,a,b):
    """ input n which is a string of the number to be changed
    'a' is an integer representing the current base
    to be changed to base b
    """
    def dec2base(i,base):
        """ INPUT integer in base 10, return string
        of Base base equivalent. """
        convertString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        if i < base:
            return convertString[i]
        else:
            return dec2base(i//base,base) + convertString[i%base]
    if a == 10:
        return dec2base(int(n),b)
    if b == 10:
        return int(str(n),a)
    elif b != 10:
        return base2base(int(str(n),a),10,b)

from itertools import permutations
perm1to8 = []
permDEC = []
permDECsorted = []
for perm in permutations('12345678'):
    perm1to8.append(''.join(perm))
    
print(perm1to8[20229], base2base(int(perm1to8[20229]), 16 , 10 ))

for p in perm1to8:
    permDEC.append(  base2base(int(p), 16 , 10 ) )

permDECsorted = sorted(permDEC)

print(base2base(int(permDEC[20229]), 10 , 16 ), permDEC[20229])
print(base2base(int(permDECsorted[20229]), 10 , 16 ), permDECsorted[20229])
  Posted by Larry on 2023-07-25 09:27:14
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