#1
22.03.2017 um 18:49 UhrHi,
probiere es z. B. mal mit 0001 oder 1112.
Grüße vom
nachbar
probiere es z. B. mal mit 0001 oder 1112.
Grüße vom
nachbar
Python :: Aufgabe #145 :: Lösung #3
import math
def array_to_number(array):
zahl = 0
for i in range(4):
if array[3-i] != 0:
zahl += int(array[3-i])*int(math.pow(10,i))
return zahl
def steps(zahl):
aufsteigend = sorted(zahl)
absteigend = sorted(zahl ,reverse=True)
return int(array_to_number(absteigend) - array_to_number(aufsteigend))
# testing number
zahl = 2351
for x in range(100):
zahl = steps(str(zahl))
print(zahl)Kommentare:
Nachbar
Punkte: 2820
30 Aufgaben
67 Lösungen
44 Kommentare