day 20 part 2 attempt

i don't think brute force is going to work
main
magical 2023-12-20 06:03:08 +00:00
parent 9165dd7d86
commit 7178a11eee
1 changed files with 22 additions and 0 deletions

View File

@ -63,6 +63,10 @@ proc pulse {init {debug 0}} {
set pulses {}
foreach {from n value} $copy {
incr count($value)
if {$n eq "rx" && $value == 0} {
global solved
set solved 1
}
switch $type($n) {
flip {
if {$value == 0} {
@ -106,11 +110,29 @@ proc solve input {
set solved 0
for {set i 1} {$i <= 1000} {incr i} {
pulse broadcaster
if {$solved} {
puts "rx $i"
}
}
puts "$count(0)"
puts $count(1)
puts [expr {$count(0) * $count(1)}]
global type
if {![info exists type(rx)]} return
while {!$solved} {
pulse broadcaster
incr i
if {$solved} {
puts "rx $i"
break
}
if {$i % 1000 == 0} {
puts "\[$i\]"
}
}
}
solve stdin