Euler program (python) problem 24

Source: Internet
Author: User

Lexicographic Permutationsproblem 24

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations is listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

012 021 102 120 201 210

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?


Go to the "thread for Problem" in the forum.

Python Code:

a=[0,1,2,3,4,5,6,7,8,9]
def func (x):
I=1
Data=1
While Data<x:
I+=1
Data*=i
Step=int (data/i)
K=1
While x-step*k>0:
K+=1
return [i,k-1,x-step* (k-1)]


Last=[];
Temp= (func (1000000))
While temp[2]>1:
If Temp[0]==len (a):
K=TEMP[1]
Last.append (A[k])
Del A[k]
Else
Last.append (A[0:-temp[0])
Del A[0:-temp[0]]
Last.append (A[temp[1])
Del A[temp[1]]
Temp=func (Temp[2])
If temp[2]==1:
Last.append (A[::-1])
Else
Last.append (a)
Print (last)

Time: <1s

Euler program (python) problem 24

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.