-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem24.py
43 lines (36 loc) · 1.01 KB
/
problem24.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import math
def numberUntil(currentlyAt, numbersLeft, limit):
mult = math.factorial(numbersLeft - 1)
n = -1
while True:
n += 1
if n*mult+currentlyAt > limit:
break
# currentlyAt += mult*(n-1)
return n-1, mult*(n-1)
if __name__ == '__main__':
digitsUsed = 10
limit = 1000000-1
# digitsUsed = 3
# limit =
currentlyAt = 0
places = []
for k in range(digitsUsed-1):
hold, toAdd = numberUntil(currentlyAt, digitsUsed-k, limit)
currentlyAt += toAdd
places.append(hold)
print(places)
digitsLeft = list(range(digitsUsed))
print(digitsLeft)
finalNumber = []
for k in range(digitsUsed-1):
# print('going to take the', places[k], 'th number from', digitsLeft)
hold = digitsLeft.pop(places[k])
# print(hold)
finalNumber.append(hold)
finalNumber.append(digitsLeft[0])
stingList = []
for k in finalNumber:
stingList.append(str(k))
A = ''.join(stingList)
print(A)