Sobes.tech
Middle+

Implement a function that takes []any and delta int. It should increase only the first occurrences of unique integers (int) by delta. Other types and repeated numbers should remain unchanged. The function should return the updated slice and two numbers: updated – how many unique numbers were changed, duplicates – how many numeric elements turned out to be duplicates func IncrementUniqueIntsInMixed(xs []any, delta int) ([]any, int, int) { // your code } // Example: xs := []any{1, "a", 5, "b", 1, 0, 5} u, d, s := IncrementUniqueIntsInMixed(xs, 3) // xs == []any{4, "a", 8, "b", 1, 3, 5} // u == 3 // unique numbers: 1, 5, 0 // d == 2 // repeated numbers: second 1, second 5

sobes.tech AI

Answer from AI

go func IncrementUniqueIntsInMixed(xs []any, delta int) ([]any, int, int) { seen := make(map[int]bool) updated := 0 duplicates := 0

for i, v := range xs {
    num, ok := v.(int)
    if !ok {
        // not a number, skip
        continue
    }

    if !seen[num] {
        // first occurrence of a unique number
        xs[i] = num + delta
        seen[num] = true
        updated++
    } else {
        // duplicate number
        duplicates++
    }
}

return xs, updated, duplicates

}


Example of usage:

```go
xs := []any{1, "a", 5, "b", 1, 0, 5}
u, d, s := IncrementUniqueIntsInMixed(xs, 3)
// xs == []any{4, "a", 8, "b", 1, 3, 5}
// u == 3 (numbers 1, 5, 0 increased)
// d == 2 (second 1 and second 5 are duplicates)
Implement a function that takes []any and delta int… - sobes.tech