27
1
Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.
Examples
[]
→ []
/[]
[42]
→ [0]
/[1]
[7,7,7]
→ [0,1,2]
/[1,2,3]
[10,20,30]
→ [0,0,0]
/[1,1,1]
[5,12,10,12,12,10]
→ [0,0,0,1,2,1]
/[1,1,1,2,3,2]
[2,7,1,8,2,8,1,8,2,8]
→ [0,0,0,0,1,1,1,2,2,3]
/[1,1,1,1,2,2,2,3,3,4]
[3,1,4,1,5,9,2,6,5,3,5,9]
→ [0,0,0,1,0,0,0,0,1,1,2,1]
/[1,1,1,2,1,1,1,1,2,2,3,2]
2So basically the number of times it has appeared the sequence so far? – Jo King – 2019-01-08T09:41:02.817
1@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice. – Adám – 2019-01-08T09:42:11.927