From 6d4851d4b453b11bf75a454e7ada10e721719918 Mon Sep 17 00:00:00 2001 From: Alexander Avery Date: Wed, 6 Dec 2023 23:09:42 -0500 Subject: [PATCH] add common use parsing file --- parse.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 parse.go diff --git a/parse.go b/parse.go new file mode 100644 index 0000000..c66ec3a --- /dev/null +++ b/parse.go @@ -0,0 +1,24 @@ +package main + +import ( + "bufio" + "strconv" + "strings" +) + +var spaceReplacer = strings.NewReplacer("\t", "", " ", "") + +func scanints(str string) []int { + ints := make([]int, 0) + scanner := bufio.NewScanner(strings.NewReader(str)) + scanner.Split(bufio.ScanWords) + + for scanner.Scan() { + val, err := strconv.Atoi(scanner.Text()) + if err != nil { + panic(err) + } + ints = append(ints, val) + } + return ints +}