Bootstrap and day 1 solution

This commit is contained in:
2022-06-06 15:14:31 -05:00
commit 662d76eb7c
13 changed files with 373 additions and 0 deletions

44
utilities/colors.go Normal file
View File

@ -0,0 +1,44 @@
package utilities
const (
ColorBlack = "\u001b[30m"
ColorRed = "\u001b[31m"
ColorGreen = "\u001b[32m"
ColorYellow = "\u001b[33m"
ColorBlue = "\u001b[34m"
ColorMagenta = "\u001b[35m"
ColorCyan = "\u001b[36m"
ColorWhite = "\u001b[37m"
ColorBrightBlack = "\u001b[30;1m"
ColorBrightRed = "\u001b[31;1m"
ColorBrightGreen = "\u001b[32;1m"
ColorBrightYellow = "\u001b[33;1m"
ColorBrightBlue = "\u001b[34;1m"
ColorBrightMagenta = "\u001b[35;1m"
ColorBrightCyan = "\u001b[36;1m"
ColorBrightWhite = "\u001b[37;1m"
BackgroundBlack = "\u001b[40m"
BackgroundRed = "\u001b[41m"
BackgroundGreen = "\u001b[42m"
BackgroundYellow = "\u001b[43m"
BackgroundBlue = "\u001b[44m"
BackgroundMagenta = "\u001b[45m"
BackgroundCyan = "\u001b[46m"
BackgroundWhite = "\u001b[47m"
BackgroundBrightBlack = "\u001b[40;1m"
BackgroundBrightRed = "\u001b[41;1m"
BackgroundBrightGreen = "\u001b[42;1m"
BackgroundBrightYellow = "\u001b[43;1m"
BackgroundBrightBlue = "\u001b[44;1m"
BackgroundBrightMagenta = "\u001b[45;1m"
BackgroundBrightCyan = "\u001b[46;1m"
BackgroundBrightWhite = "\u001b[47;1m"
TextReset = "\u001b[0m"
TextBold = "\u001b[1m"
TextUnderline = "\u001b[4m"
TextReverse = "\u001b[7m"
)

45
utilities/parsing.go Normal file
View File

@ -0,0 +1,45 @@
package utilities
import (
"bufio"
"fmt"
"strconv"
"parnic.com/aoc2019/inputs"
)
func getData(filename string, lineHandler func(line string)) {
file, err := inputs.Sets.Open(fmt.Sprintf("%s.txt", filename))
// version that doesn't use embedded files:
// file, err := os.Open(fmt.Sprintf("inputs/%s.txt", filename))
if err != nil {
panic(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
lineHandler(scanner.Text())
}
}
func GetStringLines(filename string) []string {
retval := make([]string, 0)
getData(filename, func(line string) {
retval = append(retval, line)
})
return retval
}
func GetIntLines(filename string) []int64 {
retval := make([]int64, 0)
getData(filename, func(line string) {
val, err := strconv.ParseInt(line, 10, 64)
if err != nil {
panic(err)
}
retval = append(retval, val)
})
return retval
}