Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- func main() {
- a := input()
- for {
- occurances := make(map[int]int)
- duplicates := make(map[int]int)
- fmt.Println(a)
- for i := 0; i < len(a); i++ {
- occurances[a[i]]++
- if occurances[a[i]] > 1 {
- duplicates[i] = occurances[a[i]] - 1
- }
- }
- if len(duplicates) == 0 {
- break
- }
- fmt.Println(duplicates)
- for index, offset := range duplicates {
- a[index] += offset
- delete(duplicates, index)
- }
- }
- fmt.Println(a)
- }
- func input() []int {
- return []int{
- 5, 8, 6, 1, 2, 7, 2, 5, 2, 5,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement