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

Home > Numbers
Cube Arranger (Posted on 2024-03-22) Difficulty: 3 of 5
Find the smallest distinct positive integers, M and N such that you can rearrange the digits of M to get N, and you can rearrange the digits of M3 to get N3. [Leading zeroes are not allowed.]

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 Computer solution | Comment 1 of 3
The smallest is:
(M,N) = (101, 110)
(M^3,N^3) = (1030301, 1331000)

And the next is:
(M,N) = (102, 201)
(M^3,N^3) = (1061208, 8120601)

Algorithm notes:
To determine if the digits are a rearrangement, encode each integer or cube to a string of its alphabetically sorted digits - after sorting, there may be a leading zero, so this 'key' needs to be a string rather than an integer.

For integers up to 1000, 84% have a "buddy", or can be converted to another integer by rearranging the digits.
But this is only true for 4% of cubes of integers up to 1000.

Make the first filter: eliminating cube "keys" which only have a single cube associated with them.

-------------------
big = 1000
numbDict = {}
cubeDict = {}
for k in range(1,big):
    kCubed = k**3
    numbKey = ''.join(sorted(str(k)))
    cubeKey = ''.join(sorted(str(kCubed)))
    if numbKey not in numbDict:
        numbDict[numbKey] = [k]
    else:
        numbDict[numbKey].append(k)
    if cubeKey not in cubeDict:
        cubeDict[cubeKey] = [kCubed]
    else:
        cubeDict[cubeKey].append(kCubed)

for k,v in cubeDict.items():
    if len(v) == 1:
        continue
    these_N_keys = []
    thesenumbs = []
    for cub in v:
        n = round(cub**(1/3))
        keyOfN =  ''.join(sorted(str(n)))
        these_N_keys.append(keyOfN)
        thesenumbs.append(n)
    if len(these_N_keys) == len(set(these_N_keys)):
        continue
        
    print('M and N are among:', thesenumbs )
    print('The cubes are among:', v)
    print()

  Posted by Larry on 2024-03-22 09:09:45
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 (20)
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