Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement