Press CTRL+C or CMD+C to copy the selected text and close this dialog.
Tweet
8 people like it. Like the snippet!
given an array n generates all lists with k choices from n
1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
let n_choose_k n k = let rec choose lo = function |0 -> [[]] |i -> [for j in lo .. (Array.length n)-1 do for ks in choose (j+1) (i-1) do yield n.[j] :: ks ] in choose 0 k n_choose_k [|'a' .. 'f'|] 3 ;;