diff --git a/algs4/src/meatballhat.com/algs4/io.go b/algs4/src/meatballhat.com/algs4/io.go new file mode 100644 index 0000000..2b87eec --- /dev/null +++ b/algs4/src/meatballhat.com/algs4/io.go @@ -0,0 +1,26 @@ +package algs4 + +import ( + "bufio" + "io" + "strconv" +) + +func ReadInts(infile io.Reader) ([]int64, error) { + ints := make([]int64, 0) + + var i int64 + + fileReader := bufio.NewReader(infile) + line, err := fileReader.ReadString('\n') + for err == nil { + i, err = strconv.ParseInt(line, 10, 0) + if err != nil { + return nil, err + } + ints = append(ints, i) + line, err = fileReader.ReadString('\n') + } + + return ints, nil +} diff --git a/algs4/src/meatballhat.com/algs4/io_test.go b/algs4/src/meatballhat.com/algs4/io_test.go new file mode 100644 index 0000000..14dbb73 --- /dev/null +++ b/algs4/src/meatballhat.com/algs4/io_test.go @@ -0,0 +1,11 @@ +package algs4_test + +import ( + "testing" +) + +func TestReadInts(t *testing.T) { + if 1 == 0 { + t.Error("WAT") + } +}