2017-05-04 4 views
-1

質問:入力として数字のリストを取る関数すべての置換の帰納的定義を書くと、 はリストのリストとして表される出力としてその数字のリストのすべての順列のセットを返します。スキーマ

(apply append(map(lambda (i) (map (lambda (j)(cons i j)) 
               (permute (remove i 
lst))))lst))))) 

私はこの問題のコアコードを思いついた。しかし、変数やデータ構造の変更がなく、純粋な英語と数学的表記法で解を表現する必要があります。

答えて

0
# Python program to print all permutations with 
# duplicates allowed 

def toString(List): 
    return ''.join(List) 

# Function to print permutations of string 
# This function takes three parameters: 
# 1. String 
# 2. Starting index of the string 
# 3. Ending index of the string. 
def permute(a, l, r): 
    if l==r: 
     print toString(a) 
    else: 
     for i in xrange(l,r+1): 
      a[l], a[i] = a[i], a[l] 
      permute(a, l+1, r) 
      a[l], a[i] = a[i], a[l] # backtrack 

# Driver program to test the above function 
string = "ABC" 
n = len(string) 
a = list(string) 
permute(a, 0, n-1) 

# This code is contributed by Bhavya Jain 

これはgeekforgeeks

ソースで見つかったウル問題のpythonで行わコードです:Mathword(http://mathworld.wolfram.com/Permutation.html

+0

はウルコメントありがとうございました。しかし、私はScheme言語で答えが必要です。 –

+0

@ NickSunなぜあなたはこの答えを受け入れましたか?それがあなたの要件を満たしていない場合はどうですか? –