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