From 7932dc6a5c84e9947216fa9e51a9180857a29182 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 +++++++++++++++++++++++++++++++++++++++++ inputs/day06_input | 2 ++ inputs/day06_test_input | 2 ++ 4 files changed, 76 insertions(+) create mode 120000 day06/inputs create mode 100644 day06/race.go create mode 100644 inputs/day06_input create mode 100644 inputs/day06_test_input 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) +} diff --git a/inputs/day06_input b/inputs/day06_input new file mode 100644 index 0000000..01c2b63 --- /dev/null +++ b/inputs/day06_input @@ -0,0 +1,2 @@ +Time: 59 79 65 75 +Distance: 597 1234 1032 1328 diff --git a/inputs/day06_test_input b/inputs/day06_test_input new file mode 100644 index 0000000..28f5ae9 --- /dev/null +++ b/inputs/day06_test_input @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200