The combinations solution gives the same answers as the last solution you 
posted, in reverse order.

julia> function decompose_jm(val, num)
          out = Vector{Int}[]
          for c in combinations(1:9, num)
              if sum(c) == val
                  push!(out, c)
              end
           end
           out
       end
decompose_jm (generic function with 1 method)

julia> function sub(val, num, tot, res, pos, allres)
         if val==tot && num==0
           push!(allres, res)
         elseif tot<val && num>0 && !isempty(pos)
           sub(val, num-1, tot+pos[1], push!(copy(res),pos[1]), pos[2:end], 
sub(val, num, tot, res, pos[2:end], allres))
         else
           allres
         end
       end
sub (generic function with 1 method)

julia> function decompose_pu(val, num)
         sub(val, num, 0, Int16[], 1:(max(num, 10))-1, Array[])
       end
decompose_pu (generic function with 1 method)


julia> for i in 1:45
         for j in 1:20
           if decompose_jm(i, j) != reverse(decompose_pu(i, j))
             print(i, j)
           end
         end
       end; print("success")
success



On Monday, October 19, 2015 at 10:00:12 AM UTC-4, Patrick Useldinger wrote:
>
> Jason,
> I cannot look into this right now but for sure the results are not 
> correct. 
> BTW the first version I posted does not give correct results either, but 
> the last one does.
> Thanks very much, I think my next step is to get more acquainted with 
> Julia ;-)
> -Patrick
>

Reply via email to