diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-01-19 20:34:56 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-01-19 20:34:56 +0100 |
| commit | 11394225ead868425c29df7576cdee0c22d61c5b (patch) | |
| tree | 61c07cd8567e140f52a38509292bee3308f217cf | |
| parent | fa9d49887911374b1306c57cd69de3bfeeadc548 (diff) | |
scratchdir
| -rw-r--r-- | day16.go | 51 | ||||
| -rw-r--r-- | day16.txt | 46 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | scratchdir/hashbydata.go (renamed from hashbydata.go) | 0 | ||||
| -rw-r--r-- | scratchdir/heapsort.go | 37 | ||||
| -rw-r--r-- | scratchdir/insertionsort.go | 24 | ||||
| -rw-r--r-- | scratchdir/radixsort.go (renamed from radixsort.go) | 0 | ||||
| -rw-r--r-- | scratchdir/scratch.fnl | 8 | ||||
| -rw-r--r-- | scratchdir/selectionsort.go (renamed from selectionsort.go) | 0 |
9 files changed, 169 insertions, 0 deletions
diff --git a/day16.go b/day16.go new file mode 100644 index 0000000..0fedb24 --- /dev/null +++ b/day16.go @@ -0,0 +1,51 @@ +package main + +import ( + "bufio" + "fmt" + "io" + "log" + "os" + "regexp" +) + +type Valve struct { + name string +} + +func readValves(f io.Reader) map[string]Valve { + pattern := regexp.MustCompile( + `Valve ([A-Z]+) has flow rate=(\d+); tunnels? leads? to valves? ([A-Z, ]+)`, + ) + + s := bufio.NewScanner(f) + for s.Scan() { + line := s.Text() + valveInfo := pattern.FindAllStringSubmatch(line, 3)[0] + fmt.Println(valveInfo) + } + return nil +} + +/* +AA,0 =================== +||.............\\ \\ +BB,13===CC,2===DD,20 II,0 +...............\\ \\ +...............EE,20 JJ,21 +...............\\ +...............FF,0 +...............\\ +...............GG,0 +...............\\ +...............HH,22 +Probably can do some apriori thing here +*/ +func main() { + fh, err := os.Open("day16.txt") + if err != nil { + log.Fatal("Input file not found") + } + valves := readValves(fh) + fmt.Println(valves) +} diff --git a/day16.txt b/day16.txt new file mode 100644 index 0000000..4d0dc5e --- /dev/null +++ b/day16.txt @@ -0,0 +1,46 @@ +Valve OJ has flow rate=0; tunnels lead to valves EW, IG +Valve BN has flow rate=0; tunnels lead to valves SA, AA +Valve SA has flow rate=5; tunnels lead to valves QK, LP, ZP, BN, VH +Valve RL has flow rate=21; tunnel leads to valve AM +Valve LR has flow rate=19; tunnel leads to valve XZ +Valve VQ has flow rate=0; tunnels lead to valves OW, IG +Valve ZK has flow rate=0; tunnels lead to valves EW, WC +Valve IG has flow rate=16; tunnels lead to valves OJ, VQ +Valve WC has flow rate=22; tunnels lead to valves VD, ZK +Valve EW has flow rate=18; tunnels lead to valves OJ, ZK +Valve FP has flow rate=8; tunnel leads to valve GB +Valve JF has flow rate=23; tunnel leads to valve VD +Valve BL has flow rate=0; tunnels lead to valves AA, ZD +Valve BZ has flow rate=0; tunnels lead to valves QK, JA +Valve KH has flow rate=0; tunnels lead to valves SJ, FC +Valve FU has flow rate=0; tunnels lead to valves FC, MH +Valve ZP has flow rate=0; tunnels lead to valves SA, FC +Valve DZ has flow rate=0; tunnels lead to valves AA, MH +Valve RI has flow rate=0; tunnels lead to valves LP, MH +Valve AE has flow rate=0; tunnels lead to valves FC, AA +Valve JA has flow rate=4; tunnels lead to valves MM, BZ, JR, ZI, QO +Valve XP has flow rate=0; tunnels lead to valves ZD, ZI +Valve GB has flow rate=0; tunnels lead to valves FP, SJ +Valve AM has flow rate=0; tunnels lead to valves ZD, RL +Valve MH has flow rate=3; tunnels lead to valves VJ, DZ, JR, FU, RI +Valve QK has flow rate=0; tunnels lead to valves BZ, SA +Valve AA has flow rate=0; tunnels lead to valves DZ, CZ, BL, AE, BN +Valve MJ has flow rate=0; tunnels lead to valves VN, VH +Valve QO has flow rate=0; tunnels lead to valves CZ, JA +Valve MM has flow rate=0; tunnels lead to valves FC, JA +Valve VN has flow rate=17; tunnels lead to valves FV, MJ +Valve OW has flow rate=0; tunnels lead to valves SJ, VQ +Valve ZI has flow rate=0; tunnels lead to valves XP, JA +Valve VJ has flow rate=0; tunnels lead to valves KJ, MH +Valve KQ has flow rate=0; tunnels lead to valves XZ, KJ +Valve FC has flow rate=12; tunnels lead to valves ZP, MM, KH, AE, FU +Valve LP has flow rate=0; tunnels lead to valves SA, RI +Valve VD has flow rate=0; tunnels lead to valves WC, JF +Valve JR has flow rate=0; tunnels lead to valves MH, JA +Valve VH has flow rate=0; tunnels lead to valves SA, MJ +Valve CZ has flow rate=0; tunnels lead to valves AA, QO +Valve SJ has flow rate=15; tunnels lead to valves KH, FV, GB, OW +Valve FV has flow rate=0; tunnels lead to valves VN, SJ +Valve XZ has flow rate=0; tunnels lead to valves LR, KQ +Valve KJ has flow rate=9; tunnels lead to valves KQ, VJ +Valve ZD has flow rate=13; tunnels lead to valves XP, BL, AM @@ -0,0 +1,3 @@ +module mvinkio.online/aoc + +go 1.19 diff --git a/hashbydata.go b/scratchdir/hashbydata.go index 83874f3..83874f3 100644 --- a/hashbydata.go +++ b/scratchdir/hashbydata.go diff --git a/scratchdir/heapsort.go b/scratchdir/heapsort.go new file mode 100644 index 0000000..47552af --- /dev/null +++ b/scratchdir/heapsort.go @@ -0,0 +1,37 @@ +package main + +import ( + "container/heap" + "fmt" +) + +var sortingdata []int = []int{1, 23, 4, 234, 123, 4, 4512, 0} + +type myHeap []int + +func (h myHeap) Less(i, j int) bool { return h[i] > h[j] } +func (h myHeap) Len() int { return len(h) } +func (h myHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } + +func (h *myHeap) Pop() any { + popper := *h + popped := popper[len(*h)-1] + *h = popper[:len(*h)-1] + return popped +} + +func (h *myHeap) Push(x any) { + *h = append(*h, x.(int)) +} + +func main() { + orig := myHeap(sortingdata) + heap.Init(&orig) + + end := orig.Len() - 1 + h := orig + for h.Len() > 0 { + heap.Pop(&h) + } + fmt.Println(end, orig) +} diff --git a/scratchdir/insertionsort.go b/scratchdir/insertionsort.go new file mode 100644 index 0000000..cc7d2d6 --- /dev/null +++ b/scratchdir/insertionsort.go @@ -0,0 +1,24 @@ +package main + +import "fmt" + +var sortingdata []int = []int{1, 23, 4, 234, 123, 4, 4512, 0} + +func insert(in []int) { + for i := len(in) - 1; i > 0; i-- { + if in[i-1] >= in[i] { + in[i], in[i-1] = in[i-1], in[i] + } + } +} + +func insertionSort(in []int) []int { + for i := 0; i < len(in); i++ { + insert(in[:i+1]) + } + return in +} + +func main() { + fmt.Println(insertionSort(sortingdata)) +} diff --git a/radixsort.go b/scratchdir/radixsort.go index 806a5f8..806a5f8 100644 --- a/radixsort.go +++ b/scratchdir/radixsort.go diff --git a/scratchdir/scratch.fnl b/scratchdir/scratch.fnl new file mode 100644 index 0000000..ea6dc40 --- /dev/null +++ b/scratchdir/scratch.fnl @@ -0,0 +1,8 @@ +(vim.api.nvim_create_namespace :debug) +(vim.api.nvim_buf_clear_namespace 0 41 0 -1) + +(vim.api.nvim_buf_set_extmark 0 41 1 1 + {:id 4 + :virt_text_pos :overlay + :virt_lines [[["Hi there is this cool? Making a long string hereereeeeeeeeeeeeeeeeeeeeeeeeeee hidden messages should also be visible otherwise this is pretty useless" + :DiffText]]]}) diff --git a/selectionsort.go b/scratchdir/selectionsort.go index 67a33cf..67a33cf 100644 --- a/selectionsort.go +++ b/scratchdir/selectionsort.go |
