How do I turn this into arrays?

Hi,

This code works but the output is 1 single array:

[ 10 - i - j for i in collect(0:9), j in collect(0:9) if 10- i - j > 0]

output:

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 4, 3, 2, 1, 3, 2, 1, 2, 1, 1]

How do I change it to be:

[[10,9,8,7,6,5,4,3,2,1],[9,8,7,6,5,4,3,2,1],[8,7,6,5,4,3,2,1],[7,6,5,4,3,2,1],[6,5,4,3,2,1],[5,4,3,2,1],[4,3,2,1],[3,2,1],[2,1],[1]]

What am i not doing correct?

best,

Like so?

julia> [[10 - i - j for i in 0:9 if 10- i - j > 0] for j in 0:9]
10-element Array{Array{Int64,1},1}:
 [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
 [9, 8, 7, 6, 5, 4, 3, 2, 1]    
 [8, 7, 6, 5, 4, 3, 2, 1]       

Also note that writing for i in collect(0:9) is never necessary. Just about the only reason to collect a range is if you wish to mutate the resulting Array.

2 Likes

@improbable22: you read my mind. When i saw your code I started to wonder if collect() was redundant!
So I am suppose to put the second for-loop outside to achieve this. Cool thanks!