3 ms·
some python to do this trick and find counterexamples that won't work import random as r def fnc(b): bstr = list(str(b)) if bstr.count(
by leecarraher 5y ago
some python to do this trick and find counterexamples that won't work
import random as r
def fnc(b):
bstr = list(str(b))
if bstr.count(bstr[0]) == len(bstr):
return "can't shuffle"
max_ct = len(bstr)*10
# do while
r.shuffle(bstr)
b_shuf = int(''.join(bstr))
diff = abs(b-b_shuf)
bstr = list(str(diff))
i = r.randint(0,len(bstr)-1)
while bstr[i] == '0' or bstr[i] == '9':
i = r.randint(0,len(bstr)-1)
bstr = list(str(b))
r.shuffle(bstr)
b_shuf = int(''.join(bstr))
diff = abs(b-b_shuf)
bstr = list(str(diff))
max_ct -=1
if max_ct == 0:
return "bollocks!"
del(bstr[i])
s = sum(map(int,bstr))
i =0
while (i+s) % 9 != 0:
i+=1
return bstr,i,diff