查找n个元素的所有k个组合长度

嘿我试图不使用任何模块递归地找到n个元素的所有k个组合长度

For example n = 4 so [0,1,2,3] and k=3 so the all the combination length 3 are

>>>[0,0,0],[0,0,1],[0,0,2],[0,0,3],[0,0,4],[0,1,0],[0,1,1],[0,1,2]....

I tried to think on that like a tree but i didn't mange to go from here [0,0,4] for example to here [0,1,0] all i got was [0,0,0],[0,0,1],[0,0,2],[0,0,3],[0,0,4]