This commit is contained in:
29
src-go/helpers/Day.go
Normal file
29
src-go/helpers/Day.go
Normal file
@ -0,0 +1,29 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
type DayResults struct {
|
||||
Day int `json:"day"`
|
||||
Year int `json:"year"`
|
||||
Part1Example int `json:"part1-example"`
|
||||
Part1 int `json:"part1"`
|
||||
Part2Example int `json:"part2-example"`
|
||||
Part2 int `json:"part2"`
|
||||
}
|
||||
|
||||
func PrintDayResults(results DayResults) {
|
||||
yellow := color.New(color.FgYellow).SprintFunc()
|
||||
gray := color.New(color.FgHiBlack).SprintFunc()
|
||||
|
||||
color.HiBlue("Day %d%s", results.Day, gray("/"+strconv.Itoa(results.Year)))
|
||||
color.Green(" Part 1 (example): %s", yellow(results.Part1Example))
|
||||
color.HiGreen(" Part 1 : %s", yellow(results.Part1))
|
||||
color.Blue(" " + strings.Repeat("-", 23))
|
||||
color.Green(" Part 2 (example): %s", yellow(results.Part2Example))
|
||||
color.HiGreen(" Part 2 : %s", yellow(results.Part2))
|
||||
}
|
55
src-go/helpers/ReadFileByLine.go
Normal file
55
src-go/helpers/ReadFileByLine.go
Normal file
@ -0,0 +1,55 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ReadFileByLine(path string) []string {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer func(file *os.File) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}(file)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
var returnData []string
|
||||
for scanner.Scan() {
|
||||
returnData = append(returnData, scanner.Text())
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return returnData
|
||||
}
|
||||
|
||||
func GetDayYear() (int, int) {
|
||||
// get current year
|
||||
year, _, day := time.Now().Date()
|
||||
// Change 2023 to 23
|
||||
year = year % 100
|
||||
|
||||
if len(os.Args) == 2 {
|
||||
day, _ := strconv.Atoi(os.Args[1])
|
||||
return day, year
|
||||
}
|
||||
|
||||
if len(os.Args) == 3 {
|
||||
day, _ := strconv.Atoi(os.Args[1])
|
||||
year, _ := strconv.Atoi(os.Args[2])
|
||||
|
||||
return day, year
|
||||
}
|
||||
|
||||
return day, year
|
||||
}
|
Reference in New Issue
Block a user