I am making a simple prime factor function that can put a slice that is [][]int
like
prime_factors_mult(315) => [[3,2],[5,1],[7,1]]
but instead of this result I get [[7,1][7,1][7,1][7,1]]
which is afterwards reduced to a empty slice because they repeat them selfs. I tried to look at it with step by step and it changes all the values to the last append. What should I do to avoid this ?
func prime_factors_mult(x []int)(y [][]int){// Problem 36
in :=[]int{0,0}
var k [][]int
for _,item := range x{
tok := 0
for i:=0;i<len(x);i++{
if item == x[i]{
tok++
}
}
in[0]=item
in[1]=tok
k=append(k,in)
}
for _,item := range k{
for i:=0;i<len(k);i++{
if item[0] != k[i][0]{
y = append(y,item)
}
}
}
return
}