Post Reply 
[VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" Special
06-24-2018, 02:57 PM
Post: #42
RE: [VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" ...
Here's a Python program for the sixth step:
Code:
def selfie(m, i, k, n, s):
    if i == 0:
        if n == ''.join(sorted(str(s))):
            print str(s)[::-1]
    else:
        for j in range(k, 10):
            selfie(m, i - 1, j, n + str(j), s + j ** m)

for m in range(12):
    selfie(m, m, 0, '', 0)

The following 41 selfies are listed:
Code:
0
1
2
3
4
5
6
7
8
9
073
704
351
173
8028
4361
4749
48039
72729
84745
438845
7180089
8180124
5271471
5136299
05087642
15087642
77439588
802115641
351589219
579533274
638494435
4777039764
05694046123
52249382004
30609287624
60605588394
15694046123
41919540249
97653680744
87561939628

It takes about 3 seconds to run:
Code:
real    0m2.805s
user    0m1.942s
sys    0m0.054s

Four of them start with 0:
Code:
0
073
05087642
05694046123

They might not be considered selfies which agrees with:
Quote:all 37 Selfies up to 11 digits long
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenges #23: "May the 4th Be With You !" ... - Thomas Klemm - 06-24-2018 02:57 PM



User(s) browsing this thread: 1 Guest(s)