我有一些 OCaml 代码,可以找到给定变化量的所有变化组合。我的大部分代码都在工作,但是我无法弄清楚这个递归函数将如何实际返回可能的更改组合。
let change_combos presidents =
let rec change amount coinlist = match amount with
|0 -> [[]] (*exits when nothing*)
|_ when (amount < 0) -> [] (*exits when less than 0*)
|_ -> match coinlist with
|[] -> [] (*Returns empty list, exits program*)
(*h::f -> something, using [25;10;5;1] aka all change combinations...*)
(*using recursion, going through all combinations and joining lists returned together*)
let print_the_coin_matrix_for_all_our_joy enter_the_matrix =
print_endline (join "\n" (List.map array_to_string enter_the_matrix));;
感谢您的帮助,如果我需要澄清一些事情,请告诉我:)