mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
add -f flag for passing filename
This commit is contained in:
parent
947016d43b
commit
40808475ac
@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"regexp"
|
||||
@ -16,8 +17,11 @@ var files embed.FS
|
||||
|
||||
var reNums = regexp.MustCompile(`[0-9]+`)
|
||||
|
||||
func Solve() (int, error) {
|
||||
data, _ := files.ReadFile("testdata/input.txt")
|
||||
func Solve(filename string) (int, error) {
|
||||
data, err := files.ReadFile(fmt.Sprintf("testdata/%s", filename))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
left, right, err := parseLines(r)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"slices"
|
||||
@ -16,8 +17,11 @@ var files embed.FS
|
||||
|
||||
var reNums = regexp.MustCompile(`[0-9]+`)
|
||||
|
||||
func Solve() (int, error) {
|
||||
data, _ := files.ReadFile("testdata/input.txt")
|
||||
func Solve(filename string) (int, error) {
|
||||
data, err := files.ReadFile(fmt.Sprintf("testdata/%s", filename))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
r := bytes.NewReader(data)
|
||||
left, right, err := parseLines(r)
|
||||
|
@ -5,6 +5,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
@ -13,13 +14,16 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
val, err := one.Solve()
|
||||
filename := flag.String("f", "input.txt", "input file")
|
||||
flag.Parse()
|
||||
|
||||
val, err := one.Solve(*filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("solution one: %d\n", val)
|
||||
|
||||
val, err = two.Solve()
|
||||
val, err = two.Solve(*filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user