From 32a84c2f3c64f06d6585f295d5bbf1155ef600fd Mon Sep 17 00:00:00 2001 From: Davide Oddone Date: Wed, 6 Dec 2023 22:52:25 +0100 Subject: [PATCH] First draft of day 6 --- day06/inputs | 1 + day06/race.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 120000 day06/inputs create mode 100644 day06/race.go diff --git a/day06/inputs b/day06/inputs new file mode 120000 index 0000000..a80bb2b --- /dev/null +++ b/day06/inputs @@ -0,0 +1 @@ +../inputs \ No newline at end of file diff --git a/day06/race.go b/day06/race.go new file mode 100644 index 0000000..aa2d78b --- /dev/null +++ b/day06/race.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" +// "strings" + "bufio" +// "math" + "os" + "strconv" + "regexp" + "sync" +) + +type Race struct { + mu sync.Mutex + temp_modify int +} + +func (r *Race) WeRaceBoys(wg *sync.WaitGroup) { + r.mu.Lock() + r.mu.Unlock() + wg.Done() +} + +func check(e error) { + if e != nil { + panic(e) + } +} + +func PrintAndWait(x ...any) { + fmt.Print(x...) + fmt.Scanln() +} + +func main() { + + file, err := os.Open("./inputs/day06_test_input") + check(err) + defer file.Close() + + r := Race{} + _ = r + + var wg sync.WaitGroup + _ = wg + + // Regex that finds the numbers in a row + renum := regexp.MustCompile("[0-9]+") + _ = renum + + scanner := bufio.NewScanner(file) + time, distance := make([]int, 0), make([]int, 0) + tempStrings := make([]string, 0) + // Generic, would work for more rows + for scanner.Scan() { + tempStrings = append(tempStrings, scanner.Text()) + } + // Now populate time and distance + timeStr := renum.FindAllString(tempStrings[0], - 1) + distStr := renum.FindAllString(tempStrings[1], - 1) + + // Both should be the same length + for i := range timeStr { + num, _ := strconv.Atoi(timeStr[i]) + time = append(time, num) + num, _ = strconv.Atoi(distStr[i]) + distance = append(distance, num) + } + PrintAndWait(time, distance) +}