Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Pascal-recursion combination enumerator:
let rec choose k xs =
if k = 0 then [[]]
else match xs with
| [] -> []
| h :: rest ->
List.map (fun c -> h :: c) (choose (k - 1) rest)
@ choose k rest
C(9, 4) = |choose 4 [1; ...; 9]| = 126
Tests pure-functional enumeration with List.map + closure over h,
@ append, [] | h :: rest pattern match on shrinking input.
200 baseline programs total -- milestone.
13 lines
235 B
OCaml
13 lines
235 B
OCaml
let rec choose k xs =
|
|
if k = 0 then [[]]
|
|
else
|
|
match xs with
|
|
| [] -> []
|
|
| h :: rest ->
|
|
List.map (fun c -> h :: c) (choose (k - 1) rest)
|
|
@ choose k rest
|
|
|
|
;;
|
|
|
|
List.length (choose 4 [1; 2; 3; 4; 5; 6; 7; 8; 9])
|