day20, small cleanup
This commit is contained in:
parent
98206fe6d4
commit
727099dbd9
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue