From dae0597628b0bb378d9550cffe4a32678a1c1205 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Fri, 22 Dec 2023 09:11:41 +0000 Subject: [PATCH] day 20 part 2 answer --- day20/sol.tcl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/day20/sol.tcl b/day20/sol.tcl index d10c52d..3f65530 100755 --- a/day20/sol.tcl +++ b/day20/sol.tcl @@ -115,13 +115,8 @@ proc solve input { set count(1) 0 global when - set last $when(dn) for {set i 1} {$i <= 1000} {incr i} { pulse broadcaster $i - if {$when(dn) ne $last} { - puts $when(dn) - set last $when(dn) - } } puts "$count(0)" @@ -131,10 +126,24 @@ proc solve input { global type if {![info exists type(rx)]} return + set last $when(dn) while {1} { pulse broadcaster $i if {$when(dn) ne $last} { - puts $when(dn) + # rx is connected to a conj of 4 circuits + # which each emit 1 high pulse on a periodic cycle. + # + # this could be more difficult but it turns out + # that the step when the first output is produced + # is also equal to the cycle length, + # and all the cycles are a prime number so we don't + # even need to do an lcm + set a [lmul [dict values $when(dn)]] + if {$a != 0} { + puts $a + break + } + #puts $when(dn) set last $when(dn) } incr i