Goofing around more with mechanics instead of reading the dang book
This commit is contained in:
parent
3f696f3060
commit
1ddd54676c
@ -1,19 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
import (
|
||||
"meatballhat.com/algs4"
|
||||
)
|
||||
|
||||
func main() {
|
||||
whiteListTxt, err := ioutil.ReadAll(os.Stdin)
|
||||
whiteList, err := algs4.ReadInts(bufio.NewReader(os.Stdin))
|
||||
sort.Ints(whiteList)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("UGH: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("UGH: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("YAP")
|
||||
fmt.Println("Got: ", string(whiteListTxt))
|
||||
fmt.Println("Sorted whitelist:")
|
||||
|
||||
for i := range whiteList {
|
||||
fmt.Println(i)
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ReadInts(inbuf io.Reader) ([]int64, error) {
|
||||
ints := make([]int64, 0)
|
||||
func ReadInts(inbuf io.Reader) ([]int, error) {
|
||||
ints := make([]int, 0)
|
||||
|
||||
var i int64
|
||||
var i64 int64
|
||||
|
||||
fileReader := bufio.NewReader(inbuf)
|
||||
line, err := fileReader.ReadString('\n')
|
||||
@ -19,13 +19,13 @@ func ReadInts(inbuf io.Reader) ([]int64, error) {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
if len(line) > 0 {
|
||||
i, err = strconv.ParseInt(line, 10, 0)
|
||||
i64, err = strconv.ParseInt(line, 10, 32)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ints = append(ints, i)
|
||||
ints = append(ints, int(i64))
|
||||
}
|
||||
|
||||
line, err = fileReader.ReadString('\n')
|
||||
|
Loading…
Reference in New Issue
Block a user