From 727099dbd967d73e61d7b1a55ff18712dfdf84b9 Mon Sep 17 00:00:00 2001 From: efim Date: Wed, 20 Dec 2023 13:26:34 +0000 Subject: [PATCH] day20, small cleanup --- day20/looping.go | 2 +- day20/notes.org | 5 +++++ day20/pulsePropagation.go | 22 +++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/day20/looping.go b/day20/looping.go index 559b2b5..452d28e 100644 --- a/day20/looping.go +++ b/day20/looping.go @@ -38,6 +38,7 @@ func FindSubGraphLoopLength(subgraph map[string]any, allModules map[string]Modul seenSubgraphStates := make(map[string]int) monitoredPulses = make(map[int][]PulseType) for { + monitoredPulsesOfTheStep := PropagateButtonPressWithMonitor(allModules, step, monitorOutputsOf) subgraphModules := make(map[string]Module) for key, _ := range subgraph { subgraphModules[key] = allModules[key] @@ -53,7 +54,6 @@ func FindSubGraphLoopLength(subgraph map[string]any, allModules map[string]Modul } seenSubgraphStates[subgraphState] = step - monitoredPulsesOfTheStep := PropagateButtonPressWithMonitor(allModules, step, monitorOutputsOf) if len(monitoredPulsesOfTheStep) > 0 { monitoredPulses[step] = monitoredPulsesOfTheStep } diff --git a/day20/notes.org b/day20/notes.org index 154be40..2510e65 100644 --- a/day20/notes.org +++ b/day20/notes.org @@ -172,3 +172,8 @@ so it's going to be 1 + least common ... ** aaand, i just did least common multiple of the cycle lenghts. and i didn't even added 1. which is strange. i guess i did have 'off-by-one' crap +*** yeah. i can start from step 1. but i need to first update State then check for previous + +all loops are from step 1. + +it's just for some reason code was unstable when i was searching for all diff --git a/day20/pulsePropagation.go b/day20/pulsePropagation.go index f6fc7e9..a541063 100644 --- a/day20/pulsePropagation.go +++ b/day20/pulsePropagation.go @@ -11,15 +11,15 @@ func Run() int { // fmt.Println("hello from dya 20") filename := "day20/input" - modules := ReadModules(filename) - InitStuffs(modules) + // modules := ReadModules(filename) + // InitStuffs(modules) // log.Print("got modules:\n", modules) // var low, high int // low, high = Count10000ButtonPresses(modules) // log.Printf("got low %d and high %d\n", low, high) - CheckSubgraphsStuff(modules) + CheckSubgraphsStuff(filename) var result int // result = CalcCommonStep() @@ -27,25 +27,33 @@ func Run() int { return result } -func CheckSubgraphsStuff(allModules map[string]Module) { +func CheckSubgraphsStuff(filename string) { // loopStarts := allModules["broadcast"].Outputs() // loop start and loop sink loopItems := map[string]string { - // "sr": "xn", - // "ch": "xf", - // "hd": "qn", + "sr": "xn", + "ch": "xf", + "hd": "qn", "bx": "zl", } for start, end := range loopItems { + allModules := ReadModules(filename) + InitStuffs(allModules) + log.Printf(">>> searching for loop of %s", start) themap := make(map[string]any) loopModules := TransitiveOutputs(start, allModules, themap) + // i think my bug is not to reset state of `allModules` _, _, requestedPulses := FindSubGraphLoopLength(loopModules, allModules, end) FilterMonitoredPulses(requestedPulses) log.Printf("the pulses: +%v", requestedPulses) } + + // yeah. and now all cycles start from 1 (first button press) + // and then they emit the [high low] on last step of their cycle + // so just LCM of these all } func Count10000ButtonPresses(modules map[string]Module) (lowSignalsCount, highSignalsCount int) {