相关疑难解决方法(0)

F#中的组合和排列

我最近为F#项目编写了以下组合和排列函数,但我很清楚它们远未优化.

/// Rotates a list by one place forward.
let rotate lst =
    List.tail lst @ [List.head lst]

/// Gets all rotations of a list.
let getRotations lst =
    let rec getAll lst i = if i = 0 then [] else lst :: (getAll (rotate lst) (i - 1))
    getAll lst (List.length lst)

/// Gets all permutations (without repetition) of specified length from a list.
let rec getPerms n lst = 
    match n, lst with
    | 0, _ -> …
Run Code Online (Sandbox Code Playgroud)

f# combinations permutation combinatorics

11
推荐指数
2
解决办法
4425
查看次数

标签 统计

combinations ×1

combinatorics ×1

f# ×1

permutation ×1