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)
|
seenSubgraphStates := make(map[string]int)
|
||||||
monitoredPulses = make(map[int][]PulseType)
|
monitoredPulses = make(map[int][]PulseType)
|
||||||
for {
|
for {
|
||||||
|
monitoredPulsesOfTheStep := PropagateButtonPressWithMonitor(allModules, step, monitorOutputsOf)
|
||||||
subgraphModules := make(map[string]Module)
|
subgraphModules := make(map[string]Module)
|
||||||
for key, _ := range subgraph {
|
for key, _ := range subgraph {
|
||||||
subgraphModules[key] = allModules[key]
|
subgraphModules[key] = allModules[key]
|
||||||
|
@ -53,7 +54,6 @@ func FindSubGraphLoopLength(subgraph map[string]any, allModules map[string]Modul
|
||||||
}
|
}
|
||||||
|
|
||||||
seenSubgraphStates[subgraphState] = step
|
seenSubgraphStates[subgraphState] = step
|
||||||
monitoredPulsesOfTheStep := PropagateButtonPressWithMonitor(allModules, step, monitorOutputsOf)
|
|
||||||
if len(monitoredPulsesOfTheStep) > 0 {
|
if len(monitoredPulsesOfTheStep) > 0 {
|
||||||
monitoredPulses[step] = monitoredPulsesOfTheStep
|
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.
|
** 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'
|
and i didn't even added 1. which is strange. i guess i did have 'off-by-one'
|
||||||
crap
|
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")
|
// fmt.Println("hello from dya 20")
|
||||||
|
|
||||||
filename := "day20/input"
|
filename := "day20/input"
|
||||||
modules := ReadModules(filename)
|
// modules := ReadModules(filename)
|
||||||
InitStuffs(modules)
|
// InitStuffs(modules)
|
||||||
// log.Print("got modules:\n", modules)
|
// log.Print("got modules:\n", modules)
|
||||||
|
|
||||||
// var low, high int
|
// var low, high int
|
||||||
// low, high = Count10000ButtonPresses(modules)
|
// low, high = Count10000ButtonPresses(modules)
|
||||||
// log.Printf("got low %d and high %d\n", low, high)
|
// log.Printf("got low %d and high %d\n", low, high)
|
||||||
|
|
||||||
CheckSubgraphsStuff(modules)
|
CheckSubgraphsStuff(filename)
|
||||||
|
|
||||||
var result int
|
var result int
|
||||||
// result = CalcCommonStep()
|
// result = CalcCommonStep()
|
||||||
|
@ -27,25 +27,33 @@ func Run() int {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckSubgraphsStuff(allModules map[string]Module) {
|
func CheckSubgraphsStuff(filename string) {
|
||||||
// loopStarts := allModules["broadcast"].Outputs()
|
// loopStarts := allModules["broadcast"].Outputs()
|
||||||
|
|
||||||
// loop start and loop sink
|
// loop start and loop sink
|
||||||
loopItems := map[string]string {
|
loopItems := map[string]string {
|
||||||
// "sr": "xn",
|
"sr": "xn",
|
||||||
// "ch": "xf",
|
"ch": "xf",
|
||||||
// "hd": "qn",
|
"hd": "qn",
|
||||||
"bx": "zl",
|
"bx": "zl",
|
||||||
}
|
}
|
||||||
|
|
||||||
for start, end := range loopItems {
|
for start, end := range loopItems {
|
||||||
|
allModules := ReadModules(filename)
|
||||||
|
InitStuffs(allModules)
|
||||||
|
|
||||||
log.Printf(">>> searching for loop of %s", start)
|
log.Printf(">>> searching for loop of %s", start)
|
||||||
themap := make(map[string]any)
|
themap := make(map[string]any)
|
||||||
loopModules := TransitiveOutputs(start, allModules, themap)
|
loopModules := TransitiveOutputs(start, allModules, themap)
|
||||||
|
// i think my bug is not to reset state of `allModules`
|
||||||
_, _, requestedPulses := FindSubGraphLoopLength(loopModules, allModules, end)
|
_, _, requestedPulses := FindSubGraphLoopLength(loopModules, allModules, end)
|
||||||
FilterMonitoredPulses(requestedPulses)
|
FilterMonitoredPulses(requestedPulses)
|
||||||
log.Printf("the pulses: +%v", 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) {
|
func Count10000ButtonPresses(modules map[string]Module) (lowSignalsCount, highSignalsCount int) {
|
||||||
|
|
Loading…
Reference in New Issue