proc distance {x1 y1 x2 y2} {
  set dx [expr {$x1 - $x2}]
  set dy [expr {$y1 - $y2}]
  return [expr {sqrt(($dx*$dx) + ($dy * $dy))}]
}
set router1 {100 100}
set router2 {300 300}

set locations {
  {50 50}
  {250 300}
  {150 100}
  {50 200}
}

lassign $router1 r1x r1y
lassign $router2 r2x r2y

foreach pair $locations {
  lassign $pair xl yl
  set d1 [distance $xl $yl $r1x $r1y]
  set d2 [distance $xl $yl $r2x $r2y]
  if {$d1 < $d2} {
    puts "Connect system at $pair to router1 with $d1 feet of wire"
  } else {
    puts "Connect system at $pair to router2 with $d2 feet of wire"
  }
}
