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

Home > Numbers
Triple Rearranger (Posted on 2024-03-24) Difficulty: 3 of 5
Find the smallest distinct whole numbers, M and N such that you can rearrange the digits of M to get N, you can rearrange the digits of M2 to get N2, you can rearrange the digits of M3 to get N3, and where M does not contain the digit zero.

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 1
(M,N): 495839, 539894
(M^2,N^2): 245856313921, 291485531236
(M^3,N^3): 121905148838274719, 157371289401128984

The cubes contain a zero but M and N do not.

The first output from the program below was:
M and N are among: [495839, 539894, 598529, 612581, 944441, 965891, 966161]
The squares are among: [245856313921, 291485531236, 358236963841, 375255481561, 891968802481, 932945423881, 933467077921]
The cubes are among: [121905148838274719, 157371289401128984, 214415211730789889, 229874378150118941, 842411907783958121, 901123588417842971, 901879485471231281]

The program was designed to find cubes which share the same digits, but the squares and first powers do not necessarily share the same digits.
In this case, the first two of the each list do share the same digits.

------------------------
big = 1000000
numbDict = {}
squareDict = {}
cubeDict = {}
for k in range(1,big):
    kSquared = k**2
    kCubed = k**3
    numbKey = ''.join(sorted(str(k)))
    if '0' in numbKey:
        continue
    squareKey = ''.join(sorted(str(kSquared)))
    cubeKey = ''.join(sorted(str(kCubed)))
    if numbKey not in numbDict:
        numbDict[numbKey] = [k]
    else:
        numbDict[numbKey].append(k)
        
    if squareKey not in squareDict:
        squareDict[squareKey] = [kSquared]
    else:
        squareDict[squareKey].append(kSquared)
        
    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 = []
    these_Nsqrd_keys = []
    thesenumbs = []
    thesesquares = []
    for cub in v:
        n = round(cub**(1/3))
        nsqrd = n**2
        keyOfN =  ''.join(sorted(str(n)))
        keyOfNsqrd =  ''.join(sorted(str(nsqrd)))
        these_N_keys.append(keyOfN)
        these_Nsqrd_keys.append(keyOfNsqrd)
        thesenumbs.append(n)
        thesesquares.append(n**2)
    if len(these_N_keys) == len(set(these_N_keys)):
        continue
    if len(these_Nsqrd_keys) == len(set(these_Nsqrd_keys)):
        continue
        
    print('M and N are among:', thesenumbs )
    print('The squares are among:', thesesquares)
    print('The cubes are among:', v)
    print()

  Posted by Larry on 2024-03-24 11:58:22
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 (21)
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