Browse Source

using tee reader instead of seeking; use stdin for input

master
Alexander Avery 3 weeks ago
parent
commit
addd7ac71d
  1. 14
      2024/day01.go

14
2024/day01.go

@ -2,9 +2,9 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"sort" "sort"
) )
@ -53,13 +53,9 @@ func part2(r io.Reader) string {
} }
func main() { func main() {
f, err := os.Open("day01.txt") buf := new(bytes.Buffer)
if err != nil { tee := io.TeeReader(os.Stdin, buf)
log.Fatal(err)
}
defer f.Close()
fmt.Println(part1(f)) fmt.Println(part1(tee))
f.Seek(0, 0) fmt.Println(part2(buf))
fmt.Println(part2(f))
} }

Loading…
Cancel
Save