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 from string

  • Given a string of digits, count how many times each digit appears?

Skeleton:

package main

import "fmt"

func main() {
	dgts := "3767913713127648173"
	fmt.Println(dgts)
}

Expected output:

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