Replace Recurring

Replace recurring item with count
def rep(a:var[])
{
return = [Imperative]
{
b = 0;
c = [];
e = 1;
for(d in a)
{
if(d == "unoccupied")
{
c[b] = String.PadLeft(e+"",2,"0");
b = b+1;
e = e + 1;
}
else
{
c[b] = d;
b = b + 1;
}
}
return c;
}
};