Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: count digits

  • Given a list of digits, count how many time each digit appears.

Skeleton:

package main

import "fmt"

func main() {
	digits := [...]int{3, 7, 6, 7, 9, 1, 3, 7, 8, 3, 1, 7, 0, 1, 2, 3}
	fmt.Println(digits)

	// ...
}

Expected output:

[3 7 6 7 9 1 3 7 8 3 1 7 0 1 2 3]
0: 1
1: 3
2: 1
3: 4
4: 0
5: 0
6: 1
7: 4
8: 1
9: 1