#4 Embed _blocks.csv_
This commit is contained in:
parent
c9b05e7026
commit
c02aea543c
Can't render this file because it is too large.
|
@ -1,15 +1,18 @@
|
||||
package solver
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"io"
|
||||
"embed"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO: Import at compile time, provide with the binary
|
||||
// Dirty AF. Not happy with this. 😒
|
||||
//
|
||||
//go:embed blocks.csv
|
||||
var f embed.FS
|
||||
|
||||
func (solver *Solver) load_blocks() {
|
||||
|
||||
defer solver.timeTrack(time.Now(), "Loaded blocks")
|
||||
@ -17,25 +20,21 @@ func (solver *Solver) load_blocks() {
|
||||
|
||||
var blocks []int
|
||||
|
||||
file, err := os.Open("blocks.csv")
|
||||
file, err := f.ReadFile("blocks.csv")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
r := csv.NewReader(file)
|
||||
for {
|
||||
record, err := r.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
temp := strings.Split(string(file), "\n")
|
||||
|
||||
block, _ := strconv.Atoi(record[0])
|
||||
for _, line := range temp {
|
||||
block, _ := strconv.Atoi(string(line))
|
||||
if block == 0 { // Ignore new-line at the end of the file.
|
||||
continue
|
||||
}
|
||||
blocks = append(blocks, block)
|
||||
}
|
||||
|
||||
solver.blocks = blocks
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user