SHARE
TWEET

Untitled

a guest Apr 19th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func main() {
  8.     a := input()
  9.     for {
  10.         occurances := make(map[int]int)
  11.         duplicates := make(map[int]int)
  12.         fmt.Println(a)
  13.         for i := 0; i < len(a); i++ {
  14.             occurances[a[i]]++
  15.             if occurances[a[i]] > 1 {
  16.                 duplicates[i] = occurances[a[i]] - 1
  17.             }
  18.         }
  19.  
  20.         if len(duplicates) == 0 {
  21.             break
  22.         }
  23.         fmt.Println(duplicates)
  24.  
  25.         for index, offset := range duplicates {
  26.             a[index] += offset
  27.             delete(duplicates, index)
  28.         }
  29.     }
  30.  
  31.     fmt.Println(a)
  32. }
  33.  
  34. func input() []int {
  35.     return []int{
  36.         5, 8, 6, 1, 2, 7, 2, 5, 2, 5,
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top