1:- module(canny_permutations,
2 [ permute_sum_of_int/2, 3 permute_list_to_grid/2 4 ]).
13permute_sum_of_int(0, []) :- !.
14permute_sum_of_int(N, [H|T]) :-
15 between(1, N, H),
16 N0 is N - H,
17 permute_sum_of_int(N0, T).
30permute_list_to_grid(List0, List) :-
31 length(List0, N),
32 permute_sum_of_int(N, Lengths),
33 permute_list_to_grid_(List0, Lengths, List).
34
35permute_list_to_grid_([], [], []) :- !.
36permute_list_to_grid_(List0, [H0|T0], [H|T]) :-
37 length(H, H0),
38 append(H, H_, List0),
39 permute_list_to_grid_(H_, T0, T)