Created
May 9, 2017 13:19
-
-
Save saschatimme/ad09c0e04f261c3779c94036ab7971dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exponents_helper(curr_sum::Int, target_sum::Int, remaining_elements::Int)::Vector{Vector{Int}} | |
if remaining_elements == 0 | |
return [[]] | |
end | |
if curr_sum == target_sum | |
return [zeros(Int, remaining_elements)] | |
end | |
if remaining_elements == 1 | |
return map(x-> [x], 0:(target_sum - curr_sum)) | |
end | |
results = [] | |
for x=0:(target_sum-curr_sum) | |
remaining_results = exponents_helper(curr_sum + x, target_sum, remaining_elements - 1) | |
append!(results, map(xs -> [x; xs], remaining_results)) | |
end | |
results | |
end | |
create_exponents(total_degree, nvars) = exponents_helper(0, total_degree, nvars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment