go.txt 462 B

12345678910111213141516171819202122232425
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "strings"
  7. )
  8. func readNumbers(startingNumbers string) (int, map[int][2]int) {
  9. lastNumber := 0
  10. numbersSpoken := make(map[int][2]int)
  11. for i, item := range strings.Split(string(startingNumbers), ",") {
  12. var number int
  13. n, err := fmt.Sscanf(item, "%d", &number)
  14. if err != nil || n < 1 {
  15. log.Fatal(err)
  16. }
  17. lastNumber = number
  18. numbersSpoken[number] = [2]int{i + 1, 0}
  19. }
  20. return lastNumber, numbersSpoken
  21. }