day 20 part 2 answer
parent
fd8de9c7c2
commit
dae0597628
|
@ -115,13 +115,8 @@ proc solve input {
|
||||||
set count(1) 0
|
set count(1) 0
|
||||||
|
|
||||||
global when
|
global when
|
||||||
set last $when(dn)
|
|
||||||
for {set i 1} {$i <= 1000} {incr i} {
|
for {set i 1} {$i <= 1000} {incr i} {
|
||||||
pulse broadcaster $i
|
pulse broadcaster $i
|
||||||
if {$when(dn) ne $last} {
|
|
||||||
puts $when(dn)
|
|
||||||
set last $when(dn)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
puts "$count(0)"
|
puts "$count(0)"
|
||||||
|
@ -131,10 +126,24 @@ proc solve input {
|
||||||
global type
|
global type
|
||||||
if {![info exists type(rx)]} return
|
if {![info exists type(rx)]} return
|
||||||
|
|
||||||
|
set last $when(dn)
|
||||||
while {1} {
|
while {1} {
|
||||||
pulse broadcaster $i
|
pulse broadcaster $i
|
||||||
if {$when(dn) ne $last} {
|
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)
|
set last $when(dn)
|
||||||
}
|
}
|
||||||
incr i
|
incr i
|
||||||
|
|
Loading…
Reference in New Issue